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
|
2014-07-12 03:24:27 +00:00
|
|
|
switch($full_path){
|
|
|
|
case *.html *.htm
|
|
|
|
type=text/html
|
|
|
|
case *.css
|
|
|
|
type=text/css
|
2019-06-20 06:56:03 +00:00
|
|
|
case *.txt *.md
|
2019-06-17 03:47:16 +00:00
|
|
|
type=text/plain
|
2014-07-12 03:24:27 +00:00
|
|
|
case *.jpg *.jpeg
|
|
|
|
type=image/jpeg
|
|
|
|
case *.gif
|
|
|
|
type=image/gif
|
|
|
|
case *.png
|
|
|
|
type=image/png
|
|
|
|
case *
|
|
|
|
type=`{file -m $full_path}
|
|
|
|
}
|
2019-06-17 03:47:16 +00:00
|
|
|
if(~ $type text/*)
|
|
|
|
type=$type^'; charset=utf-8'
|
2014-07-12 03:24:27 +00:00
|
|
|
max_age=3600 # 1 hour
|
2013-02-04 22:40:05 +00:00
|
|
|
echo 'HTTP/1.1 200 OK'^$cr
|
|
|
|
emit_extra_headers
|
2019-06-17 03:43:40 +00:00
|
|
|
echo 'Content-type: '^$type^$cr
|
2020-01-07 06:58:59 +00:00
|
|
|
echo 'Content-length: '^`{ls -l $full_path | awk '{print $6}'}^$cr
|
2013-02-04 22:40:05 +00:00
|
|
|
echo 'Cache-control: max-age='^$max_age^$cr
|
|
|
|
echo $cr
|
|
|
|
exec cat $full_path
|