Mercurial > repos > rhope
comparison 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 |
comparison
equal
deleted
inserted
replaced
46:429b5f441381 | 47:6202b866d72c |
---|---|
32 out <- HTTP Response[client, type, content length, headers, "200 OK"] | 32 out <- HTTP Response[client, type, content length, headers, "200 OK"] |
33 } | 33 } |
34 | 34 |
35 HTTP Response[client,type,content length,headers,code:out] | 35 HTTP Response[client,type,content length,headers,code:out] |
36 { | 36 { |
37 start headers <- [New@Dictionary[]]Set["Content-Type", type] | 37 start headers <- [Dictionary[]]Set["Content-Type", type] |
38 If[[content length] < [0]] | 38 If[[content length] < [0]] |
39 { | 39 { |
40 default headers <- [start headers]Set["Transfer-Encoding", "Chunked"] | 40 default headers <- [start headers]Set["Transfer-Encoding", "Chunked"] |
41 }{ | 41 }{ |
42 default headers <- [start headers]Set["Content-Length", content length] | 42 default headers <- [start headers]Set["Content-Length", content length] |
57 } | 57 } |
58 | 58 |
59 HTTP Not Found[client] | 59 HTTP Not Found[client] |
60 { | 60 { |
61 string <- "<html><head><title>Document Not Found</title></head><body>The document you requested is not available on this server.</body></html>" | 61 string <- "<html><head><title>Document Not Found</title></head><body>The document you requested is not available on this server.</body></html>" |
62 HTTP Response[client, Get Content Type[".html"], [string]Length, New@Dictionary[], "404 Not Found"] | 62 HTTP Response[client, Get Content Type[".html"], [string]Length, Dictionary[], "404 Not Found"] |
63 { | 63 { |
64 [~]Put String[string] | 64 [~]Put String[string] |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
73 { | 73 { |
74 handlerpath <- ["/"]Append[~] | 74 handlerpath <- ["/"]Append[~] |
75 }{ | 75 }{ |
76 handlerpath <- "/" | 76 handlerpath <- "/" |
77 } | 77 } |
78 [handler]Index[handlerpath] | 78 host <- [headers]Index["Host"] {} |
79 { | |
80 host <- "" | |
81 } | |
82 | |
83 the handler <- [handler]Index[[host]Append[handlerpath]] {} | |
84 { | |
85 the handler <- [handler]Index[handlerpath] {} | |
86 { | |
87 ,newpath <- [path]Slice[1] | |
88 If[[newpath] = ["default.css"]] | |
89 { | |
90 file <- <String@File[newpath] | |
91 content length <- Length[file] | |
92 If[[content length] > [0]] | |
93 { | |
94 junk,data <- [file]Get FString[content length] | |
95 [HTTP OK[client, Get Content Type[path], content length, Dictionary[]] | |
96 ]Put String@Net Client[data] | |
97 }{ | |
98 HTTP Not Found[client] | |
99 } | |
100 }{ | |
101 HTTP Not Found[client] | |
102 } | |
103 } | |
104 } | |
105 | |
106 Val[the handler] | |
79 { | 107 { |
80 If[[[parts]Length] > [1]] | 108 If[[[parts]Length] > [1]] |
81 { | 109 { |
82 queryvars <- Dict Split[[parts]Index[1], "=", "&"] | 110 queryvars <- Dict Split[[parts]Index[1], "=", "&"] |
83 }{ | 111 }{ |
84 queryvars <- New@Dictionary[] | 112 queryvars <- Dictionary[] |
85 } | 113 } |
86 [~]Do@Worker[ [[[[[New@List[]]Append[client]]Append[path]]Append[type]]Append[queryvars]]Append[headers] ] | 114 [~]Do@Worker[ [[[[[List[]]Append[client]]Append[path]]Append[type]]Append[queryvars]]Append[headers] ] |
87 }{ | |
88 | |
89 ,newpath <- [path]Slice[1] | |
90 file <- <String@File[newpath] | |
91 content length <- Length[file] | |
92 If[[content length] > [0]] | |
93 { | |
94 junk,data <- [file]Get FString[content length] | |
95 [HTTP OK[client, Get Content Type[path], content length, New@Dictionary[]] | |
96 ]Put String@Net Client[data] | |
97 }{ | |
98 HTTP Not Found[client] | |
99 } | |
100 } | 115 } |
101 | 116 |
102 } | 117 } |
103 | 118 |
104 Connection Start[con,handlers] | 119 Connection Start[con,handlers] |