Rewrite http post parsing code, this should be faster and cleaner, added a
get_post_args function to keep backwards compat but it is not really needed. Fix a silly bug in urldecode.
This commit is contained in:
parent
04f6550a53
commit
3bdb99773b
2 changed files with 22 additions and 21 deletions
|
|
@ -25,34 +25,33 @@ fn static_file {
|
||||||
|
|
||||||
|
|
||||||
# Status is () if at least one arg is found.
|
# Status is () if at least one arg is found.
|
||||||
fn get_post_args {
|
# Note: should check if content type is application/x-www-form-urlencoded?
|
||||||
_status='Args not found'
|
fn load_post_args {
|
||||||
if(! ~ $REQUEST_METHOD POST)
|
if(~ $REQUEST_METHOD POST && ~ $#post_args 0) {
|
||||||
_status='No http post!'
|
|
||||||
if not if(~ $#POST_ARGS 0) {
|
|
||||||
ifs='&
|
ifs='&
|
||||||
' for(pair in `{cat}) {
|
' for(pair in `{cat}) {
|
||||||
pair=`{echo -n $pair | sed 's/=/\&/'}
|
ifs='=' { pair=`{echo -n $pair} }
|
||||||
# Maybe we should urldecode on the first pass?
|
n='post_arg_'^`{echo $pair(1)|tr -cd 'a-zA-Z0-9_'}
|
||||||
POST_ARGS=( $POST_ARGS $pair )
|
post_args=( $post_args $n )
|
||||||
_get_post_args_set_var $pair $*
|
$n=`{echo -n $pair(2) | urldecode}
|
||||||
}
|
}
|
||||||
|
pair=()
|
||||||
}
|
}
|
||||||
if not {
|
if not
|
||||||
pair=$POST_ARGS
|
status='No POST or post args already loaded'
|
||||||
while(! ~ $#pair 0) {
|
}
|
||||||
_get_post_args_set_var $pair $*
|
fn get_post_args {
|
||||||
pair=$pair(3-)
|
load_post_args
|
||||||
|
_status='No post arg matches'
|
||||||
|
for(n in $*) {
|
||||||
|
v=post_arg_$n
|
||||||
|
if(! ~ $#$v 0) {
|
||||||
|
$n=$$v
|
||||||
|
_status=()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status=$_status
|
status=$_status
|
||||||
}
|
}
|
||||||
fn _get_post_args_set_var {
|
|
||||||
if(~ $1 $*(3-)) {
|
|
||||||
ifs=() { $1=`{echo -n $2 | urldecode | tr -d '
'} }
|
|
||||||
_status=()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# This seems slightly improve performance, but might depend on httpd buffering behavior.
|
# This seems slightly improve performance, but might depend on httpd buffering behavior.
|
||||||
fn awk_buffer {
|
fn awk_buffer {
|
||||||
|
|
@ -104,7 +103,7 @@ BEGIN {
|
||||||
decoded = decoded c
|
decoded = decoded c
|
||||||
++i
|
++i
|
||||||
}
|
}
|
||||||
printf decoded
|
printf "%s", decoded
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
siteTitle='werc'
|
siteTitle='werc'
|
||||||
siteSubTitle=' Bringing minimalism and sanity to the web'
|
siteSubTitle=' Bringing minimalism and sanity to the web'
|
||||||
|
enable_comments=yes
|
||||||
|
enabled_apps=($enabled_apps hello dirdir bridge)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue