shithub: werc

Download patch

ref: 8e997ffe8fbea9cb99ad97ef4c452f6048900c2c
parent: c3ccac5cf92d5766e2922eba818ba4ae2ef5df90
author: uriel <uriel@suckless.org>
date: Sun Sep 14 17:38:38 EDT 2008

Add a web server in rc by maht

diff: cannot open b/bin/contrib//null: file does not exist: 'b/bin/contrib//null'
--- /dev/null
+++ b/bin/contrib/webserver.rc
@@ -1,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