- New static_file and select_mime functions.

- Minor improvements to get_post_args, set status unless one of the requested args is present.
This commit is contained in:
Uriel 2009-01-11 04:02:07 +01:00
parent f785c96fbb
commit 11900bdb0e

View file

@ -16,27 +16,42 @@ Location: '^$1^'
exit exit
} }
fn static_file {
echo 'Content-Type: '`{select_mime $1}
echo
cat $1
exit
}
# Status is () if at least one arg is found.
fn get_post_args { fn get_post_args {
if(~ $#POST_ARGS 0) { _status='Args not found'
if(! ~ $REQUEST_METHOD POST)
_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/=/\&/'} \ pair=`{echo -n $pair | sed 's/=/\&/'}
# Maybe we should urldecode on the first pass? # Maybe we should urldecode on the first pass?
POST_ARGS=( $POST_ARGS $pair ) POST_ARGS=( $POST_ARGS $pair )
ifs=() \ _get_post_args_set_var $pair $*
if(~ $pair(1) $*)
$pair(1)=`{echo -n $pair(2) | urldecode | tr -d ' '}
} }
} }
if not { if not {
pa=$POST_ARGS pair=$POST_ARGS
while(! ~ $#pa 0) { while(! ~ $#pair 0) {
ifs=() \ _get_post_args_set_var $pair $*
if(~ $pa(1) $*) pair=$pair(3-)
$pa(1)=`{echo -n $pa(2) | urldecode | tr -d ' '}
pa=$pa(3-)
} }
} }
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.
@ -131,6 +146,22 @@ fn get_cookie {
{ for(c in $co) echo $c } | sed -n 's/[^=]*=//p' { for(c in $co) echo $c } | sed -n 's/[^=]*=//p'
} }
fn select_mime {
m='text/plain'
if(~ $1 *.css)
m='text/css'
if not if(~ $1 *.ico)
m='image/x-icon'
if not if(~ $1 *.png)
m='image/png'
if not if(~ $1 *.jpg *.jpeg)
m='image/jpeg'
if not if(~ $1 *.gif)
m='image/gif'
if not if(~ $1 *.pdf)
m='application/pdf'
echo $m
}
############################################## ##############################################
# Generic rc programming helpers # Generic rc programming helpers
@ -247,7 +278,7 @@ fn make_blog_post {
################################### ###################################
# App framework # App framework
fn select_apps { fn init_apps {
found=() found=()
for(a in $enabled_apps) { for(a in $enabled_apps) {
. ./apps/$a/app.rc . ./apps/$a/app.rc