diff options
author | stanley lieber <stanley.lieber@gmail.com> | 2013-02-04 16:40:05 -0600 |
---|---|---|
committer | stanley lieber <stanley.lieber@gmail.com> | 2013-02-04 16:40:05 -0600 |
commit | c877493fb00717de1a22860d88efb75ebf14ebec (patch) | |
tree | cb3cb0e47598e2880cdd20367925102856d41a5d /rc/bin/rc-httpd/handlers/serve-static | |
parent | 0b212ed5054cd08bbc14a12936c07bc1ff5890a2 (diff) | |
download | plan9front-c877493fb00717de1a22860d88efb75ebf14ebec.tar.xz |
add rc-httpd
Diffstat (limited to 'rc/bin/rc-httpd/handlers/serve-static')
-rwxr-xr-x | rc/bin/rc-httpd/handlers/serve-static | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/rc/bin/rc-httpd/handlers/serve-static b/rc/bin/rc-httpd/handlers/serve-static new file mode 100755 index 000000000..3f7544286 --- /dev/null +++ b/rc/bin/rc-httpd/handlers/serve-static @@ -0,0 +1,30 @@ +#!/bin/rc +full_path=`{echo $"FS_ROOT^$"PATH_INFO | urlencode -d} +full_path=$"full_path +if(~ $full_path */) + error 503 +if(test -d $full_path){ + redirect perm $"location^'/' \ + 'URL not quite right, and browser did not accept redirect.' + exit +} +if(! test -e $full_path){ + error 404 + exit +} +if(! test -r $full_path){ + error 503 + exit +} +do_log 200 +type=`{file -m $full_path} +if(~ $type text/*) + max_age=3600 # 1 hour +if not + max_age=604800 # 1 week +echo 'HTTP/1.1 200 OK'^$cr +emit_extra_headers +echo 'Content-type: '^$type^$cr +echo 'Cache-control: max-age='^$max_age^$cr +echo $cr +exec cat $full_path |