werc-1.5.0-tweaks

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

webserver.rc (571B)


      1 #!/bin/rc
      2 
      3 # A web server in rc by maht
      4 # Originally from http://www.proweb.co.uk/~matt/rc/webserver.rc
      5 
      6 ifs=' '
      7 request=`{sed 1q}
      8 
      9 url=$request(2)
     10 file=`{echo $url | sed 's/http:\/\/[^\/]*//' | tr -d \012}
     11 
     12 if(test -d $file){
     13 	file=$file ^'/index.html'
     14 }
     15 if(test -e $file) {
     16 	response='200'
     17 }
     18 if not {
     19 	response='404'
     20 	file='404.html'
     21 }
     22 
     23 echo 'HTTP/1.1 ' ^$response
     24 echo 'Date: ' `{date}
     25 echo 'Server: rc shell'
     26 echo 'Content-Length: ' `{cat $file | wc -c | tr -d ' '}
     27 echo 'Content-Type: ' `{file -i $file  | awk '{ print $2 }'}
     28 echo 'Connection: close'
     29 echo
     30 cat $file