summaryrefslogtreecommitdiffstats
path: root/htgen.sh
diff options
context:
space:
mode:
authortv <tv@vix>2010-02-02 04:49:37 +0100
committertv <tv@vix>2010-02-02 04:49:37 +0100
commit466b8c5103208e7393fdb710d275e7d687be2592 (patch)
tree15a9c626d3d738f2bc5ae612d45e57357865f9e4 /htgen.sh
parent5160b7d9d657d637f3c135d4b8bb9bf31cfd4ce7 (diff)
Added default cases for $Host and $Method
Added default case for $Host: Forbidded Added default case for $Method: Not Implemented Added preliminary Cache-Control
Diffstat (limited to 'htgen.sh')
-rwxr-xr-xhtgen.sh116
1 files changed, 67 insertions, 49 deletions
diff --git a/htgen.sh b/htgen.sh
index c76283a..262e81b 100755
--- a/htgen.sh
+++ b/htgen.sh
@@ -2,8 +2,12 @@
set -euf
+# TODO Cache-Control [RFC 2616, Section 14.9]
+# TODO Accept-Encoding: gzip,deflate
+# TODO Keep-Alive: 300
+# TODO Connection: keep-alive
-Server='httpd-single/0.2'
+Server='htgen'
Request="$(sed 's/\r$//;/^$/q')"
date="`date '+%Y-%m-%d %H:%M:%S'`"
@@ -33,27 +37,28 @@ cat>&2<<EOF
## $date, $TCPREMOTEIP:$TCPREMOTEPORT $Request_Line
$Request
EOF
- if test -z "$Request_Line" ; then
- echo "# FAIL"
- exit -23
- fi >&2
-
- # TODO Date: `date --utc`
+
+##
+## Handle request.
+##
+if test -z "$Request_Line" ; then
+ echo "# FAIL"
+ exit -23
+fi >&2
- ##
- ## Handle request.
- ##
- case "$Host" in
- src.mine.nu:42380|src.mine.nu|vix|vix:42380|localhost:42380)
- case "${Method-Invalid-Request}" in
- GET|HEAD)
- case "$Request_URI" in
- /style5.css)
- body_type=file
- body=~/public_html$Request_URI
- cat<<EOF
+# TODO Date: `date --utc`
+
+case "$Host" in
+ src.mine.nu:42380|src.mine.nu|vix|vix:42380|localhost:42380)
+ case "${Method-Invalid-Request}" in
+ GET|HEAD)
+ case "$Request_URI" in
+ /style5.css)
+ body_type=file
+ body=~/public_html$Request_URI
+ cat<<EOF
HTTP/1.0 200 OK
-Connection: Close
+Connection: close
Content-Length: `du -b $body | cut -f1`
Content-Type: text/css
Server: $Server
@@ -65,22 +70,27 @@ EOF
body=~/public_html$Request_URI
cat<<EOF
HTTP/1.0 200 OK
-Connection: Close
+Connection: close
Content-Length: `du -b $body | cut -f1`
Content-Type: image/png
Server: $Server
+Cache-Control: public
EOF
;;
/|/index.html)
+ # TODO 304 Not Modified
+ # TODO better max-age(?)
+ # TODO may we use more than one Cache-Control?
body_type=file
body=~/public_html/index.html
cat<<EOF
HTTP/1.0 200 OK
Content-Type: text/html; charset=UTF-8
Server: $Server
-Connection: Close
+Connection: close
Content-Length: `du -b $body | cut -f1`
+Cache-Control: max-age=60
EOF
;;
@@ -91,47 +101,55 @@ EOF
HTTP/1.0 404 Not Found
Content-Type: text/plain; charset=UTF-8
Server: $Server
-Connection: Close
+Connection: close
Content-Length: ${#body}
EOF
;;
esac
-
- case "$Method" in
- GET)
- case "$body_type" in
- file) cat "$body" ;;
- string) echo "$body" ;;
- esac
- ;;
- esac
;;
*) # Method
+ body_type=string
+ body="501 Not Implemented: $Method"
+ cat<<EOF
+HTTP/1.0 501 Not Implemented
+Content-Type: text/plain; charset=UTF-8
+Server: $Server
+Connection: close
+Content-Length: ${#body}
+Cache-Control: public
+
+EOF
;;
esac
;;
*) # Host
+ body_type=string
+ body="403 Forbidden"
+ cat<<EOF
+HTTP/1.1 403 Forbidden
+Content-Type: text/plain; charset=UTF-8
+Connection: close
+Content-Length: ${#body}
+Cache-Control: public
+
+EOF
;;
esac
+##
+## Print message-body.
+##
+case "$Method" in
+ GET)
+ case "$body_type" in
+ file) cat "$body" ;;
+ string) echo -n "$body" ;;
+ esac
+ ;;
+esac
+
+
# Success (mod transfer)
echo "# OK" >&2
exit
-
-# tcpserver info:
-# $PROTO is the string TCP.
-#
-# $TCPLOCALIP is the IP address of the local host, in dotted-decimal form.
-#
-# $TCPLOCALPORT is the local TCP port number, in decimal.
-#
-# $TCPLOCALHOST is the name listed in DNS for the local host. If no name is available, $TCPLOCALHOST is not set. Beware that $TCPLOCALHOST can contain arbitrary characters.
-#
-# $TCPREMOTEIP is the IP address of the remote host, in dotted-decimal form.
-#
-# $TCPREMOTEPORT is the remote TCP port number, in decimal.
-#
-# $TCPREMOTEHOST is the name listed in DNS for the remote host. If no name is available, $TCPREMOTEHOST is not set. Beware that $TCPREMOTEHOST can contain arbitrary characters.
-#
-# $TCPREMOTEINFO is a connection-specific string supplied by the remote host via the 931/1413/IDENT/TAP protocol. If no information is available, $TCPREMOTEINFO is not set. Beware that $TCPREMOTEINFO can contain arbitrary characters.