Changeset 87 for branches/DirectWeb/UHTTPServer.pas
- Timestamp:
- Dec 17, 2009, 9:36:15 AM (15 years ago)
- Location:
- branches/DirectWeb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DirectWeb
- Property svn:ignore
-
old new 3 3 WoWHostingWebServer 4 4 Config.xml 5 Session
-
- Property svn:ignore
-
branches/DirectWeb/UHTTPServer.pas
r86 r87 59 59 procedure Add(AName: string; AHandler: TRequestEvent); 60 60 function IndexOfName(AName: string): TRequestHandler; 61 end; 62 63 { THTTPSession } 64 65 THTTPSession = class 66 Variables: TStringList; 67 procedure Load(Request: THTTPRequest); virtual; 68 procedure Save(Response: THTTPResponse); virtual; 69 constructor Create; virtual; 70 destructor Destroy; override; 61 71 end; 62 72 … … 73 83 MaxConnection: Integer; 74 84 RequestHandlerList: TRequestHandlerList; 85 SessionHandler: THTTPSession; 75 86 procedure FileResponse(Request: THTTPRequest; 76 87 Response: THTTPResponse); … … 103 114 repeat 104 115 Line := RecvString(10000); 105 LineParts := Explode(' ', Line); 106 if (LineIndex = 0) and (Length(LineParts) >= 3) then begin 107 Request.Method := LineParts[0]; 108 if Pos('?', LineParts[1]) > 0 then begin 109 Request.Path := Copy(LineParts[1], 1, Pos('?', LineParts[1]) - 1); 110 Request.Query.Parse(Copy(LineParts[1], Pos('?', LineParts[1]) + 1, Length(LineParts[1]))); 111 end else Request.Path := LineParts[1]; 112 end else 113 if (Length(LineParts) >= 2) and (LineParts[0][Length(LineParts[0])] = ':') then begin 114 LineParts[0] := Copy(LineParts[0], 1, Length(LineParts[0]) - 1); 115 Request.Headers.Values[LineParts[0]] := LineParts[1]; 116 if (LineIndex = 0) then begin 117 LineParts := Explode(' ', Line); 118 if (Length(LineParts) >= 3) then begin 119 Request.Method := LineParts[0]; 120 if Pos('?', LineParts[1]) > 0 then begin 121 Request.Path := Copy(LineParts[1], 1, Pos('?', LineParts[1]) - 1); 122 Request.Query.Parse(Copy(LineParts[1], Pos('?', LineParts[1]) + 1, Length(LineParts[1]))); 123 end else Request.Path := LineParts[1]; 124 end; 125 end else begin 126 LineParts := Explode(' ', Line, 2); 127 if (Length(LineParts) = 2) and (LineParts[0][Length(LineParts[0])] = ':') then begin 128 LineParts[0] := Copy(LineParts[0], 1, Length(LineParts[0]) - 1); 129 Request.Headers.Values[LineParts[0]] := LineParts[1]; 130 WriteLn(Line); 131 end; 116 132 end; 117 133 Inc(LineIndex); 118 134 until Line = ''; 119 135 120 // Parse cookies 121 if Request.Cookies.IndexOfName('Cookie') <> -1 then 122 Request.Cookies.Parse(Request.Headers.Values['Cookie']); 136 // Process cookies 137 if Request.Headers.IndexOfName('Cookie') <> -1 then 138 Request.Cookies.Parse(Request.Headers.Values['Cookie']); 139 140 // Process session 141 if Assigned(SessionHandler) then 142 SessionHandler.Load(Request); 123 143 124 144 Response.Stream.Clear; … … 130 150 if Assigned(RequestHandler) then RequestHandler.Handler(Request, Response) 131 151 else ErrorResponse(Request, Response); 152 153 if Assigned(SessionHandler) then 154 SessionHandler.Save(Response); 132 155 133 156 with Response do begin … … 139 162 // Handle cookies 140 163 for I := 0 to Cookies.Count - 1 do 141 Headers. Values['Set-Cookie'] := Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I];164 Headers.Add('Set-Cookie' + Headers.NameValueSeparator + Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I]); 142 165 // + ';path=/;expires=' + RFC822DateTime(Now); 143 166 144 167 // Send headers 145 for I := 0 to Headers.Count - 1 do 168 for I := 0 to Headers.Count - 1 do begin 169 WriteLn(Headers.Names[I] + ': ' + Headers.ValueFromIndex[I] + #13#10); 146 170 SendString(Headers.Names[I] + ': ' + Headers.ValueFromIndex[I] + #13#10); 171 end; 147 172 SendString(#13#10); 148 173 SendBuffer(Stream.Memory, Stream.Size); … … 304 329 end; 305 330 331 { THTTPSession } 332 333 procedure THTTPSession.Load(Request: THTTPRequest); 334 begin 335 336 end; 337 338 procedure THTTPSession.Save(Response: THTTPResponse); 339 begin 340 341 end; 342 343 constructor THTTPSession.Create; 344 begin 345 Variables := TStringList.Create; 346 end; 347 348 destructor THTTPSession.Destroy; 349 begin 350 Variables.Destroy; 351 inherited Destroy; 352 end; 353 306 354 end. 307 355
Note:
See TracChangeset
for help on using the changeset viewer.