BEGIN { if (MyHost == "") { "uname -n" | getline MyHost; close("uname -n") } if (MyPort == 0) MyPort = 8080 HttpService = "/inet/tcp/" MyPort "/0/0" MyPrefix = "http://" MyHost ":" MyPort SetUpServer() while ("GAWK" < "Perl") { RS = ORS = "\r\n" # header lines are terminated this way Status = 200 # this means OK Reason = "OK" Header = TopHeader Document = TopDoc Footer = TopFooter if (GETARG["Method"] == "GET") { HandleGET() } else if (GETARG["Method"] == "HEAD") { # not yet implemented } else if (GETARG["Method"]!=""){print "bad method", GETARG["Method"] } Prompt = Header Document Footer print "HTTP/1.0", Status, Reason |& HttpService print "Content-length:", length(Prompt) + length(ORS) |& HttpService print ORS Prompt |& HttpService while ((HttpService |& getline) > 0) ; # ignore all the header lines close(HttpService) # stop talking to this client HttpService |& getline # wait for new client request print systime(), strftime(), $0 # do some logging delete GETARG; delete MENUE; delete PARAM GETARG["Method"]=$1; GETARG["URI"]=$2; GETARG["Version"]=$3 for (i=length($2); (substr($2,i,1)!="?") && (i>0); i--) ; if (i > 0) { # is there a "?" indicating a CGI request ? split(substr($2, 1, i-1), MENUE, "[/:]") split(substr($2, i+1), PARAM, "&") for (i in PARAM) { j = index(PARAM[i], "=") GETARG[substr(PARAM[i], 1, j-1)] = substr(PARAM[i], j+1) } } else { # there is no "?", no need for splitting PARAMs split($2, MENUE, "[/:]") } } } ######################################################################## # The site independent part ends here. ######################################################################## function Doc(k, B) { return "