summaryrefslogtreecommitdiff
path: root/rc/bin/rc-httpd
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-06-02 16:56:19 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2015-06-02 16:56:19 +0200
commit1a1863e5dc8913e47b16e44499a3cc735aead394 (patch)
tree0ec02b693b9b52d25c1c7dc7e685f69a0d67a0c5 /rc/bin/rc-httpd
parent8caf4d3bcbabe28d34556ea6b5542b491ea43e27 (diff)
downloadplan9front-1a1863e5dc8913e47b16e44499a3cc735aead394.tar.xz
rc-httpd: cleanup cgi handler
- avoid silly stats and checks for $cgi_dir, just use status from builtin cd. - log proper http status code from the cgi script
Diffstat (limited to 'rc/bin/rc-httpd')
-rwxr-xr-xrc/bin/rc-httpd/handlers/cgi38
1 files changed, 15 insertions, 23 deletions
diff --git a/rc/bin/rc-httpd/handlers/cgi b/rc/bin/rc-httpd/handlers/cgi
index 574cd13c3..2c9a9b9b8 100755
--- a/rc/bin/rc-httpd/handlers/cgi
+++ b/rc/bin/rc-httpd/handlers/cgi
@@ -1,51 +1,43 @@
#!/bin/rc
fn filter_headers{
- response='HTTP/1.1 200 OK'^$cr
+ response=(200 OK)
lines=''
done=false
while(~ $done false){
line=`{getline}
head=`{echo $line | awk '{print tolower($1)}'}
- if(~ $head status:*){
- tmp=`{echo $line | awk '{$1="" ; print}'}
- response='HTTP/1.1 '^$"tmp^$cr
- }
+ if(~ $head status:*)
+ response=`{echo $line | awk '{$1="" ; print}'}
if not if(~ $line '')
done=true
if not
lines=$"lines^$"line^$cr^'
'
}
- echo $response
+ echo 'HTTP/1.1' $"response^$cr
echo -n $"lines
+ do_log $response(1)
}
fn run_cgi {
- path=$cgi_path exec $"cgi_bin $params
+ path=$cgi_path exec $"cgi_bin $params || echo 'Status: 500'
}
cgi_bin=$1
-if(! ~ $cgi_bin /*){
- pwd=`{pwd}
- cgi_bin=$"pwd ^ / ^ $cgi_bin
-}
-
-cgi_dir=$*($#*)
-if(! test -d $cgi_dir){
- cgi_dir=`{basename -d $cgi_dir}
+cgi_dir=.
+if(! ~ $#* 1)
+ cgi_dir=$*($#*)
+if not if(~ $"cgi_bin /*){
+ cgi_dir=`{basename -d $"cgi_bin}
cgi_dir=$"cgi_dir
}
-
-if(! test -d $"cgi_dir){
+if(! ~ $"cgi_bin */*)
+ cgi_bin=./$"cgi_bin
+if(! builtin cd $"cgi_dir >[2]/dev/null || ! test -x $"cgi_bin){
error 500
exit
}
-if(! test -f $cgi_bin -x $cgi_bin){
- error 500
- exit
-}
-do_log 200
-builtin cd $"cgi_dir
+
run_cgi | {
filter_headers
emit_extra_headers