Changeset 376
- Timestamp:
- Jun 18, 2012, 10:42:17 PM (12 years ago)
- Location:
- Network/CoolWeb
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
Network/CoolWeb/Common/UMemoryStreamEx.pas
r94 r376 46 46 function Sum: Byte; 47 47 procedure FillByte(Data: Byte; Count: Integer); 48 procedure Assign(Source: TMemoryStreamEx); 48 49 constructor Create; 49 50 property Endianness: TEndianness read FEndianness write SetEndianness; … … 204 205 end; 205 206 207 procedure TMemoryStreamEx.Assign(Source: TMemoryStreamEx); 208 var 209 OldPosition: Int64; 210 begin 211 FEndianness := Source.FEndianness; 212 SwapData := Source.SwapData; 213 OldPosition := Source.Position; 214 Clear; 215 Source.Position := 0; 216 CopyFrom(Source, Source.Size); 217 Position := OldPosition; 218 Source.Position := OldPosition; 219 end; 220 206 221 function TMemoryStreamEx.ReadWord: Word; 207 222 begin -
Network/CoolWeb/WebServer/UHTTPServer.pas
r311 r376 7 7 uses 8 8 Classes, SysUtils, UTCPServer, UCommon, UMemoryStreamEx, UMIMEType, 9 Synautil, SpecializedList ;9 Synautil, SpecializedList, SpecializedDictionary; 10 10 11 11 type … … 31 31 Content: TMemoryStreamEx; 32 32 Query: TQueryParameterList; 33 QueryParts: TListString; 34 Path: string; 33 Path: TListString; 35 34 Method: string; 36 Headers: T StringList;35 Headers: TDictionaryStringString; 37 36 Cookies: TCookieList; 38 37 Post: TQueryParameterList; 38 procedure Assign(Source: THTTPRequest); 39 39 procedure Clear; 40 40 constructor Create; … … 47 47 ContentType: string; 48 48 Content: TMemoryStreamEx; 49 Headers: T StringList;49 Headers: TDictionaryStringString; 50 50 Cookies: TCookieList; 51 procedure Assign(Source: THTTPResponse); 51 52 procedure Clear; 52 53 constructor Create; … … 62 63 SessionId: string; 63 64 Session: TStringList; 64 constructor Create; 65 procedure Assign(Source: THTTPHandlerData); 66 constructor Create; virtual; 65 67 destructor Destroy; override; 66 68 end; … … 145 147 WriteString('<h5>Request HTTP headers</h5>'); 146 148 for I := 0 to Request.Headers.Count - 1 do begin; 147 WriteString(Request.Headers. Strings[I]+ '<br/>');149 WriteString(Request.Headers.Items[I].Value + '<br/>'); 148 150 end; 149 151 … … 171 173 with Response.Content do 172 174 for I := 0 to Response.Headers.Count - 1 do begin; 173 WriteString(Response.Headers. Strings[I]+ '<br/>');175 WriteString(Response.Headers.Items[I].Value + '<br/>'); 174 176 end; 175 177 … … 184 186 begin 185 187 with HandlerData, Response.Content do begin 186 WriteString('<html><body>' + Format(SPageNotFound, [Request.Path ]) + '</body></html>');188 WriteString('<html><body>' + Format(SPageNotFound, [Request.Path.Implode('/', StrToStr)]) + '</body></html>'); 187 189 end; 188 190 end; … … 206 208 begin 207 209 with HandlerData do begin 208 FileName := DocumentRoot + Request.Path;210 FileName := DocumentRoot + DirectorySeparator + Request.Path.Implode('/', StrToStr); 209 211 if FileExists(FileName) then begin 210 212 Response.Headers.Values['Content-Type'] := GetMIMEType(Copy(ExtractFileExt(FileName), 2, 255)); 211 BinaryFile := TFileStream.Create(FileName, fmOpenRead); 212 Response.Content.WriteStream(BinaryFile, BinaryFile.Size); 213 BinaryFile.Destroy; 213 try 214 BinaryFile := TFileStream.Create(FileName, fmOpenRead); 215 Response.Content.WriteStream(BinaryFile, BinaryFile.Size); 216 finally 217 BinaryFile.Free; 218 end; 214 219 end else 215 220 with Response.Content do begin 216 WriteLn(Format(SFileNotFound, [Request.Path ]));217 WriteString('<html><body>' + Format(SFileNotFound, [Request.Path ]) + '</body></html>');221 WriteLn(Format(SFileNotFound, [Request.Path.Implode('/', StrToStr)])); 222 WriteString('<html><body>' + Format(SFileNotFound, [Request.Path.Implode('/', StrToStr)]) + '</body></html>'); 218 223 end; 219 224 end; … … 234 239 { THTTPResponse } 235 240 241 procedure THTTPResponse.Assign(Source: THTTPResponse); 242 begin 243 Content.Assign(Source.Content); 244 ContentType := Source.ContentType; 245 Cookies.Assign(Source.Cookies); 246 Headers.Assign(Source.Headers); 247 end; 248 236 249 procedure THTTPResponse.Clear; 237 250 begin … … 245 258 Content := TMemoryStreamEx.Create; 246 259 Cookies := TCookieList.Create; 247 Headers := T StringList.Create;260 Headers := TDictionaryStringString.Create; 248 261 end; 249 262 … … 277 290 { THTTPRequest } 278 291 292 procedure THTTPRequest.Assign(Source: THTTPRequest); 293 begin 294 Content.Assign(Source.Content); 295 ContentType := Source.ContentType; 296 Cookies.Assign(Source.Cookies); 297 Headers.Assign(Source.Headers); 298 Post.Assign(Source.Post); 299 Method := Source.Method; 300 Query.Assign(Source.Query); 301 Path.Assign(Source.Path); 302 end; 303 279 304 procedure THTTPRequest.Clear; 280 305 begin 281 306 Post.Clear; 282 307 Content.Clear; 283 QueryParts.Clear;308 Path.Clear; 284 309 Cookies.Clear; 285 310 Headers.Clear; … … 291 316 Post := TQueryParameterList.Create; 292 317 Query := TQueryParameterList.Create; 293 QueryParts:= TListString.Create;294 Headers := T StringList.Create;318 Path := TListString.Create; 319 Headers := TDictionaryStringString.Create; 295 320 Cookies := TCookieList.Create; 296 321 Content := TMemoryStreamEx.Create; … … 302 327 Post.Free; 303 328 Query.Free; 304 QueryParts.Free;329 Path.Free; 305 330 Headers.Free; 306 331 Cookies.Free; … … 400 425 401 426 { THTTPHandlerData } 427 428 procedure THTTPHandlerData.Assign(Source: THTTPHandlerData); 429 begin 430 Request.Assign(Source.Request); 431 Response.Assign(Source.Response); 432 Session.Assign(Source.Session); 433 Server := Source.Server; 434 SessionId := Source.SessionId; 435 end; 402 436 403 437 constructor THTTPHandlerData.Create; -
Network/CoolWeb/WebServer/UHTTPServerCGI.pas
r311 r376 99 99 EnvVars.Values['QUERY_STRING'] := Copy(EnvVars.Values['QUERY_STRING'], 1, 100 100 Length(EnvVars.Values['QUERY_STRING']) - 1); 101 Request. QueryParts.Explode(EnvVars.Values['QUERY_STRING'], '/', StrToStr);102 if Pos('?', EnvVars.Values['REQUEST_URI']) > 0 then 101 Request.Path.Explode(EnvVars.Values['QUERY_STRING'], '/', StrToStr); 102 if Pos('?', EnvVars.Values['REQUEST_URI']) > 0 then begin 103 103 Request.Query.Parse(Copy(EnvVars.Values['REQUEST_URI'], 104 104 Pos('?', EnvVars.Values['REQUEST_URI']) + 1, 105 105 Length(EnvVars.Values['REQUEST_URI']))); 106 end; 106 107 107 108 // Load session variables … … 119 120 120 121 Response.Content.Clear; 121 Response.Headers. Values['Content-type'] := 'text/html';122 Response.Headers.Add('Content-type', 'text/html'); 122 123 123 124 // Execute content handler … … 132 133 // Generate cookies 133 134 for I := 0 to Cookies.Count - 1 do 134 Headers.Add('Set-Cookie' + Headers.NameValueSeparator +Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I]);135 Headers.Add('Set-Cookie', Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I]); 135 136 // + ';path=/;expires=' + RFC822DateTime(Now); 136 137 137 138 // Generate headers 138 139 for I := 0 to Headers.Count - 1 do begin 139 WriteLn(Headers. Names[I] + ': ' + Headers.ValueFromIndex[I]);140 WriteLn(Headers.Keys[I] + ': ' + Headers.Items[I].Value); 140 141 end; 141 142 -
Network/CoolWeb/WebServer/UHTTPServerTCP.pas
r311 r376 51 51 52 52 Response := THTTPResponse.Create; 53 Response.Headers. Values['Server'] := Name;53 Response.Headers.Add('Server', Name); 54 54 Request := THTTPRequest.Create; 55 55 LineIndex := 0; … … 63 63 Request.Method := LineParts[0]; 64 64 if Pos('?', LineParts[1]) > 0 then begin 65 Request.Path := Copy(LineParts[1], 1, Pos('?', LineParts[1]) - 1);66 65 Request.Query.Parse(Copy(LineParts[1], Pos('?', LineParts[1]) + 1, Length(LineParts[1]))); 67 end else Request.Path := LineParts[1]; 66 Request.Path.Explode(Copy(LineParts[1], 1, Pos('?', LineParts[1]) - 1), '/', StrToStr); 67 end else begin 68 Request.Path.Explode(LineParts[1], '/', StrToStr); 69 Request.Query.Clear; 70 end; 68 71 end; 69 72 end else begin … … 71 74 if (LineParts.Count = 2) and (LineParts[0][Length(LineParts[0])] = ':') then begin 72 75 LineParts[0] := Copy(LineParts[0], 1, Length(LineParts[0]) - 1); 73 Request.Headers. Values[LineParts[0]] := LineParts[1];76 Request.Headers.Add(LineParts[0], LineParts[1]); 74 77 //WriteLn(Line); 75 78 end; … … 82 85 83 86 // Process cookies 84 if Request.Headers. IndexOfName('Cookie') <> -1 then87 if Request.Headers.SearchKey('Cookie') <> -1 then 85 88 Request.Cookies.Parse(Request.Headers.Values['Cookie']); 86 89 … … 90 93 91 94 Response.Content.Clear; 92 Response.Headers. Values['Content-Type'] := 'text/html';95 Response.Headers.Add('Content-Type', 'text/html'); 93 96 94 97 if Assigned(OnRequest) then OnRequest(HandlerData) … … 101 104 with Response do begin 102 105 SendString('HTTP/1.0 200 OK'#13#10); 103 Headers. Values['Content-Length'] := IntToStr(Content.Size);104 Headers. Values['Connection'] := 'close';105 Headers. Values['Date'] := RFC822DateTime(Now);106 Headers.Add('Content-Length', IntToStr(Content.Size)); 107 Headers.Add('Connection', 'close'); 108 Headers.Add('Date', RFC822DateTime(Now)); 106 109 107 110 // Handle cookies 108 111 for I := 0 to Cookies.Count - 1 do 109 Headers.Add('Set-Cookie' + Headers.NameValueSeparator +Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I]);112 Headers.Add('Set-Cookie', Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I]); 110 113 // + ';path=/;expires=' + RFC822DateTime(Now); 111 114 112 115 // Send headers 113 116 for I := 0 to Headers.Count - 1 do begin 114 //WriteLn(Headers.Names[I] + ': ' + Headers.ValueFromIndex[I]+ #13#10);115 SendString(Headers. Names[I] + ': ' + Headers.ValueFromIndex[I]+ #13#10);117 WriteLn(Headers.Keys[I] + ': ' + Headers.Items[I].Value + #13#10); 118 SendString(Headers.Keys[I] + ': ' + Headers.Items[I].Value + #13#10); 116 119 end; 117 120 SendString(#13#10); -
Network/CoolWeb/WebServer/UHTTPServerTurboPower.pas
r357 r376 47 47 Response.Content.Position := 0; 48 48 FormWebBrowser.HtmlSource := Response.Content.ReadString; 49 //FormWebBrowser.IpHtmlPanel1.SetHtmlFromStr(FormWebBrowser.HtmlSource);49 FormWebBrowser.IpHtmlPanel1.SetHtmlFromStr(FormWebBrowser.HtmlSource); 50 50 finally 51 51 Free; -
Network/CoolWeb/WebServer/UWebApp.pas
r375 r376 125 125 begin 126 126 with HandlerData do begin 127 if Request. QueryParts.Count > 0 then PageName := Request.QueryParts[0]127 if Request.Path.Count > 0 then PageName := Request.Path[0] 128 128 else PageName := ''; 129 129 Page := FindByName(PageName); -
Network/CoolWeb/WebServer/UWebPage.pas
r254 r376 10 10 type 11 11 TOnProduceEvent = procedure(HandlerData: THTTPHandlerData) of object; 12 12 13 13 14 { TWebPage }
Note:
See TracChangeset
for help on using the changeset viewer.