Further cleanup and simplification of redirect code.
This commit is contained in:
parent
e74f2966ca
commit
d12c13ee25
3 changed files with 15 additions and 15 deletions
|
|
@ -6,7 +6,7 @@ fn dprintv { { for(v in $*) { echo -n $v^'#'^$#$v^'=' $$v '; ' }; echo } >[1=2]
|
|||
fn escape_html { sed 's/&/\&/g; s/</\</g; s/>/\>/g' $* }
|
||||
|
||||
fn http_redirect {
|
||||
if(~ $1 http:* https:*)
|
||||
if(~ $1 http://* https://*)
|
||||
t=$1
|
||||
if not if(~ $1 /*)
|
||||
t=$"base_url^$1
|
||||
|
|
|
|||
22
bin/werc.rc
22
bin/werc.rc
|
|
@ -40,6 +40,7 @@ fn werc_exec_request {
|
|||
|
||||
# Note: $REQUEST_URI is not officially in CGI 1.1, but seems to be de-facto
|
||||
req_path=`{echo -n $REQUEST_URI | sed 's/\?.*//; s!//+!/!g; s/'^$forbidden_uri_chars^'//g; s/\.\.*/./g; 1q'}
|
||||
req_url=$base_url^$req_path
|
||||
local_path=$sitedir$req_path
|
||||
ifs='/' { args=`{echo -n $req_path} }
|
||||
|
||||
|
|
@ -85,18 +86,19 @@ fn werc_exec_request {
|
|||
|
||||
if(~ $#perm_redir_to 1)
|
||||
perm_redirect $perm_redir_to
|
||||
f=();t=()
|
||||
p=();
|
||||
for(i in $perm_redir_patterns) {
|
||||
if(~ $#f 0)
|
||||
f=$i
|
||||
if(~ $#p 0)
|
||||
p=$i
|
||||
if not {
|
||||
t=$i
|
||||
# TODO: should handle absolute and relative urls differently.
|
||||
from=$base_url^$req_path
|
||||
to=`{ echo $from | sed 's!'$f'!'$t'!' }
|
||||
if(! ~ $to $from)
|
||||
perm_redirect $to
|
||||
f=()
|
||||
# If target is absolute, require patern matches whole string
|
||||
if(~ $i http://* https://)
|
||||
p='^'$p
|
||||
t=`{ echo $req_path | sed 's!'$p'!'$i'!' }
|
||||
|
||||
if(! ~ $"t '' && ! ~ $t $req_path)
|
||||
perm_redirect $t
|
||||
p=()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,15 +2,13 @@
|
|||
fn conf_perm_redirect {
|
||||
if(~ $#* 1)
|
||||
perm_redir_to=$1
|
||||
if not {
|
||||
if not
|
||||
perm_redir_patterns=($perm_redir_patterns $1 $2)
|
||||
conf_hide_paths $1 # XXX Will hide paths even if replacement string is the same as matched sctring.
|
||||
}
|
||||
}
|
||||
|
||||
fn conf_hide_paths {
|
||||
for(i in $*)
|
||||
dirfilter=$dirfilter^'/'^`{echo $sitedir'/'$i|sed 's!/+!\\/!g'}^'/d; '
|
||||
dirfilter=$dirfilter^'/'^`{echo $sitedir$conf_wd$i|sed 's!/+!\\/!g'}^'/d; '
|
||||
}
|
||||
|
||||
# Usually will be called from within conf_enable_foo
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue