2013-02-04 16:40:05 -06:00
|
|
|
#!/bin/rc
|
|
|
|
full_path=`{echo $"FS_ROOT^$"PATH_INFO | urlencode -d}
|
|
|
|
full_path=$"full_path
|
2022-04-01 01:59:47 +00:00
|
|
|
if(! ~ `{cleanname -d$FS_ROOT $full_path} `{cleanname $FS_ROOT}^*){
|
|
|
|
error 503
|
|
|
|
exit
|
|
|
|
}
|
2013-02-04 16:40:05 -06:00
|
|
|
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-11 23:24:27 -04:00
|
|
|
switch($full_path){
|
|
|
|
case *.html *.htm
|
|
|
|
type=text/html
|
|
|
|
case *.css
|
|
|
|
type=text/css
|
2019-06-20 16:26:03 +09:30
|
|
|
case *.txt *.md
|
2019-06-17 13:17:16 +09:30
|
|
|
type=text/plain
|
2014-07-11 23:24:27 -04: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 13:17:16 +09:30
|
|
|
if(~ $type text/*)
|
|
|
|
type=$type^'; charset=utf-8'
|
2014-07-11 23:24:27 -04:00
|
|
|
max_age=3600 # 1 hour
|
2013-02-04 16:40:05 -06:00
|
|
|
echo 'HTTP/1.1 200 OK'^$cr
|
|
|
|
emit_extra_headers
|
2019-06-17 13:13:40 +09:30
|
|
|
echo 'Content-type: '^$type^$cr
|
2020-01-07 17:28:59 +10:30
|
|
|
echo 'Content-length: '^`{ls -l $full_path | awk '{print $6}'}^$cr
|
2013-02-04 16:40:05 -06:00
|
|
|
echo 'Cache-control: max-age='^$max_age^$cr
|
|
|
|
echo $cr
|
|
|
|
exec cat $full_path
|