Mercurial > repos > rhope
diff webserver.rhope @ 142:7bbdc034e347
Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 21 Nov 2010 16:33:17 -0500 |
parents | 6202b866d72c |
children | 1f39e69446f9 |
line wrap: on
line diff
--- a/webserver.rhope Sat Nov 20 17:48:22 2010 -0500 +++ b/webserver.rhope Sun Nov 21 16:33:17 2010 -0500 @@ -1,4 +1,3 @@ -Import extendlib.rhope Get Content Type[path:out] { @@ -42,7 +41,7 @@ default headers <- [start headers]Set["Content-Length", content length] } - out <- [client]Put String@Net Client[ + out <- [client]Put String[ [ [ [ @@ -87,13 +86,14 @@ ,newpath <- [path]Slice[1] If[[newpath] = ["default.css"]] { - file <- <String@File[newpath] + file <- Open[File[newpath],"r"] content length <- Length[file] If[[content length] > [0]] { - junk,data <- [file]Get FString[content length] + data <- [file]Read[content length] [HTTP OK[client, Get Content Type[path], content length, Dictionary[]] - ]Put String@Net Client[data] + ]Write[data] + { Close[file] } }{ HTTP Not Found[client] } @@ -118,12 +118,12 @@ Connection Start[con,handlers] { - client, request <- [con]Get DString@Net Client["\r\n"] - parts <- [request]Split@String[" "] + client, request <- [con]Get DString["\r\n"] + parts <- [request]Split[" "] Print[request] - [client]Get DString@Net Client["\r\n\r\n"] + [client]Get DString["\r\n\r\n"] { - Handle Request[~, [parts]Index@List[0], [parts]Index@List[1], headers, handlers] + Handle Request[~, [parts]Index[0], [parts]Index[1], headers, handlers] }{ headers <- Map[Dict Split[~, ":", "\r\n"], ["Trim"]Set Input[1, " \t"]] }