changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > werc / bin/contrib/webserver.rc

changeset 672: cd59fedffc2e
parent: 25f3f9eca929
child: 7c6ea8abd5f2
author: sl
date: Fri, 02 Dec 2016 20:35:58 -0500
permissions: -rwxr-xr-x
description: etc/initrc: change default markdown formatter from markdown.pl (no modern perl on plan 9) to md2html.awk (works everywhere)
1 #!/usr/local/plan9/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