diff webserver.rhope @ 47:6202b866d72c

Cleaned up constructor names and merged some other changes in to support the Rhope website
author Mike Pavone <pavone@retrodev.com>
date Tue, 22 Dec 2009 01:22:09 -0500
parents 76568becd6d6
children 7bbdc034e347
line wrap: on
line diff
--- a/webserver.rhope	Tue Dec 01 03:59:31 2009 -0500
+++ b/webserver.rhope	Tue Dec 22 01:22:09 2009 -0500
@@ -34,7 +34,7 @@
 
 HTTP Response[client,type,content length,headers,code:out]
 {
-	start headers <- [New@Dictionary[]]Set["Content-Type", type]
+	start headers <- [Dictionary[]]Set["Content-Type", type]
 	If[[content length] < [0]]
 	{
 		default headers <- [start headers]Set["Transfer-Encoding", "Chunked"]
@@ -59,7 +59,7 @@
 HTTP Not Found[client]
 {
 	string <- "<html><head><title>Document Not Found</title></head><body>The document you requested is not available on this server.</body></html>"
-	HTTP Response[client, Get Content Type[".html"], [string]Length, New@Dictionary[], "404 Not Found"]
+	HTTP Response[client, Get Content Type[".html"], [string]Length, Dictionary[], "404 Not Found"]
 	{
 		[~]Put String[string]
 	}
@@ -75,28 +75,43 @@
 	}{
 		handlerpath <- "/"
 	}
-	[handler]Index[handlerpath]
+	host <- [headers]Index["Host"] {}
+	{
+		host <- ""
+	}
+	
+	the handler <- [handler]Index[[host]Append[handlerpath]] {}
+	{
+		the handler <- [handler]Index[handlerpath] {}
+		{
+			,newpath <- [path]Slice[1]
+			If[[newpath] = ["default.css"]]
+			{
+			file <- <String@File[newpath]
+			content length <- Length[file]
+			If[[content length] > [0]]
+			{
+				junk,data <- [file]Get FString[content length]
+				[HTTP OK[client, Get Content Type[path], content length, Dictionary[]]
+				]Put String@Net Client[data]
+			}{
+				HTTP Not Found[client]
+			}
+			}{
+				HTTP Not Found[client]
+			}
+		}
+	}
+
+	Val[the handler]
 	{
 		If[[[parts]Length] > [1]]
 		{
 			queryvars <- Dict Split[[parts]Index[1], "=", "&"]
 		}{
-			queryvars <- New@Dictionary[]
+			queryvars <- Dictionary[]
 		}
-		[~]Do@Worker[ [[[[[New@List[]]Append[client]]Append[path]]Append[type]]Append[queryvars]]Append[headers] ]
-	}{
-
-		,newpath <- [path]Slice[1]
-		file <- <String@File[newpath]
-		content length <- Length[file]
-		If[[content length] > [0]]
-		{
-			junk,data <- [file]Get FString[content length]
-			[HTTP OK[client, Get Content Type[path], content length, New@Dictionary[]]
-			]Put String@Net Client[data]
-		}{
-			HTTP Not Found[client]
-		}
+		[~]Do@Worker[ [[[[[List[]]Append[client]]Append[path]]Append[type]]Append[queryvars]]Append[headers] ]
 	}
 	
 }