2013-02-04 22:40:05 +00:00
|
|
|
#!/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
|
2013-02-20 00:13:32 +00:00
|
|
|
echo 'Content-type: '^$type^'; charset=utf-8'^$cr
|
2014-02-22 07:24:37 +00:00
|
|
|
echo 'Content-length: '^`{ls -l $full_path | awk '{print $6}'}
|
2013-02-04 22:40:05 +00:00
|
|
|
echo 'Cache-control: max-age='^$max_age^$cr
|
|
|
|
echo $cr
|
|
|
|
exec cat $full_path
|