swerc

anselm's simpler werc fork
git clone git://git.suckless.org/swerc
Log | Files | Refs | README

commit 35d3e31e663495bad2c83bcb3e0ca641e1e5dfd2
parent 298e0f0299c6516fecd4c2ee011948318506af36
Author: uriel@suckless.org <unknown>
Date:   Sun, 14 Sep 2008 21:38:38 +0200

Add a web server in rc by maht
Diffstat:
Abin/contrib/webserver.rc | 30++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)

diff --git a/bin/contrib/webserver.rc b/bin/contrib/webserver.rc @@ -0,0 +1,30 @@ +#!/usr/local/plan9/bin/rc + +# A web server in rc by maht +# Originally from http://www.proweb.co.uk/~matt/rc/webserver.rc + +ifs = ' ' +request = `{sed 1q} + +url = $request(2) +file = `{echo $url | sed 's/http:\/\/[^\/]*//' | tr -d \012} + +if(test -d $file){ + file = $file ^'/index.html' +} +if (test -e $file) { + response = '200' +} +if not { + response = '404' + file = '404.html' +} + +echo 'HTTP/1.1 ' ^$response +echo 'Date: ' `{date} +echo 'Server: rc shell' +echo 'Content-Length: ' `{cat $file | wc -c | tr -d ' '} +echo 'Content-Type: ' `{file -i $file | awk ' { print $2 } '} +echo 'Connection: close' +echo +cat $file