comparison 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
comparison
equal deleted inserted replaced
141:f2cb85c53ced 142:7bbdc034e347
1 Import extendlib.rhope
2 1
3 Get Content Type[path:out] 2 Get Content Type[path:out]
4 { 3 {
5 parts <- [path]Split["."] 4 parts <- [path]Split["."]
6 ext <- [parts]Index[ [[parts]Length] - [1] ] 5 ext <- [parts]Index[ [[parts]Length] - [1] ]
40 default headers <- [start headers]Set["Transfer-Encoding", "Chunked"] 39 default headers <- [start headers]Set["Transfer-Encoding", "Chunked"]
41 }{ 40 }{
42 default headers <- [start headers]Set["Content-Length", content length] 41 default headers <- [start headers]Set["Content-Length", content length]
43 } 42 }
44 43
45 out <- [client]Put String@Net Client[ 44 out <- [client]Put String[
46 [ 45 [
47 [ 46 [
48 [ 47 [
49 ["HTTP/1.1 "]Append[code] 48 ["HTTP/1.1 "]Append[code]
50 ]Append["\r\n"] 49 ]Append["\r\n"]
85 the handler <- [handler]Index[handlerpath] {} 84 the handler <- [handler]Index[handlerpath] {}
86 { 85 {
87 ,newpath <- [path]Slice[1] 86 ,newpath <- [path]Slice[1]
88 If[[newpath] = ["default.css"]] 87 If[[newpath] = ["default.css"]]
89 { 88 {
90 file <- <String@File[newpath] 89 file <- Open[File[newpath],"r"]
91 content length <- Length[file] 90 content length <- Length[file]
92 If[[content length] > [0]] 91 If[[content length] > [0]]
93 { 92 {
94 junk,data <- [file]Get FString[content length] 93 data <- [file]Read[content length]
95 [HTTP OK[client, Get Content Type[path], content length, Dictionary[]] 94 [HTTP OK[client, Get Content Type[path], content length, Dictionary[]]
96 ]Put String@Net Client[data] 95 ]Write[data]
96 { Close[file] }
97 }{ 97 }{
98 HTTP Not Found[client] 98 HTTP Not Found[client]
99 } 99 }
100 }{ 100 }{
101 HTTP Not Found[client] 101 HTTP Not Found[client]
116 116
117 } 117 }
118 118
119 Connection Start[con,handlers] 119 Connection Start[con,handlers]
120 { 120 {
121 client, request <- [con]Get DString@Net Client["\r\n"] 121 client, request <- [con]Get DString["\r\n"]
122 parts <- [request]Split@String[" "] 122 parts <- [request]Split[" "]
123 Print[request] 123 Print[request]
124 [client]Get DString@Net Client["\r\n\r\n"] 124 [client]Get DString["\r\n\r\n"]
125 { 125 {
126 Handle Request[~, [parts]Index@List[0], [parts]Index@List[1], headers, handlers] 126 Handle Request[~, [parts]Index[0], [parts]Index[1], headers, handlers]
127 }{ 127 }{
128 headers <- Map[Dict Split[~, ":", "\r\n"], ["Trim"]Set Input[1, " \t"]] 128 headers <- Map[Dict Split[~, ":", "\r\n"], ["Trim"]Set Input[1, " \t"]]
129 } 129 }
130 } 130 }
131 131