werc-1.5.0-tweaks

Tweaks for the werc website builder created by the mad architect Uriel
Log | Files | Refs | README

serve-static (931B)


      1 #!/bin/rc
      2 full_path=`{echo $"FS_ROOT^$"PATH_INFO | urldecode.awk}
      3 full_path=$"full_path
      4 if(~ $full_path */)
      5 	error 503
      6 if(test -d $full_path){
      7 	redirect perm $"location^'/' \
      8 		'URL not quite right, and browser did not accept redirect.'
      9 	exit
     10 }
     11 if(! test -e $full_path){
     12 	error 404
     13 	exit
     14 }
     15 if(! test -r $full_path){
     16 	error 503
     17 	exit
     18 }
     19 do_log 200
     20 switch($full_path){
     21 case *.html *.htm
     22         type=text/html
     23 case *.css
     24         type=text/css
     25 case *.txt
     26         type='text/plain; charset=utf-8'
     27 case *.jpg *.jpeg
     28         type=image/jpeg
     29 case *.gif
     30         type=image/gif
     31 case *.png
     32         type=image/png
     33 case *
     34 		type=`{file -m $full_path || file -i $full_path}        # GROSS
     35 }
     36 max_age=3600	# 1 hour
     37 echo 'HTTP/1.1 200 OK'^$cr
     38 emit_extra_headers
     39 echo 'Content-type: '^$type^'; charset=utf-8'^$cr
     40 echo 'Content-length: '^`{ls -l $full_path | awk '{print $6}'}
     41 echo 'Cache-control: max-age='^$max_age^$cr
     42 echo $cr
     43 exec cat $full_path