Changeset 138 for trunk/Packages/CoolWeb/WebServer/UHTTPServerTCP.pas
- Timestamp:
- Sep 9, 2022, 8:20:25 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/CoolWeb/WebServer/UHTTPServerTCP.pas
r137 r138 4 4 5 5 uses 6 Classes, SysUtils, UHTTPServer, UTCPServer, SpecializedList, SynaUtil; 6 Classes, SysUtils, UHTTPServer, UTCPServer, SynaUtil, Generics.Collections, 7 UGenerics; 7 8 8 9 type … … 42 43 I: Integer; 43 44 ContentLength: Integer; 45 Value: string; 46 Item: TPair<string, string>; 44 47 begin 45 48 with TTCPClientThread(Sender), Socket do begin … … 60 63 WriteLn(IntToStr(Id) + ' ' + Line); 61 64 if (LineIndex = 0) then begin 62 LineParts.Explode( Line, ' ', StrToStr);65 LineParts.Explode(' ', Line); 63 66 if (LineParts.Count >= 3) then begin 64 67 Request.Method := LineParts[0]; 65 68 if Pos('?', LineParts[1]) > 0 then begin 66 69 Request.Query.Parse(Copy(LineParts[1], Pos('?', LineParts[1]) + 1, Length(LineParts[1]))); 67 Request.Path.Explode( Copy(LineParts[1], 1, Pos('?', LineParts[1]) - 1), '/', StrToStr);70 Request.Path.Explode('/', Copy(LineParts[1], 1, Pos('?', LineParts[1]) - 1)); 68 71 end else begin 69 Request.Path.Explode( LineParts[1], '/', StrToStr);72 Request.Path.Explode('/', LineParts[1]); 70 73 Request.Query.Clear; 71 74 end; … … 75 78 end; 76 79 end else begin 77 LineParts.Explode( Line, ' ', StrToStr, 2);80 LineParts.Explode(' ', Line, 2); 78 81 if (LineParts.Count = 2) and (LineParts[0][Length(LineParts[0])] = ':') then begin 79 82 LineParts[0] := Copy(LineParts[0], 1, Length(LineParts[0]) - 1); 80 83 Request.Headers.Add(LineParts[0], LineParts[1]); 81 //WriteLn(Line);82 84 end; 83 85 end; … … 86 88 87 89 if Request.Method = 'POST' then begin 88 ContentLength := StrToInt(Request.Headers.Values['Content-Length']); 90 if Request.Headers.TryGetValue('Content-Length', Value) then 91 ContentLength := StrToInt(Value); 89 92 SetLength(Line, ContentLength); 90 93 RecvBufferEx(PByte(Line), ContentLength, 1000); … … 96 99 97 100 // Process cookies 98 if Request.Headers. SearchKey('Cookie') <> -1then99 Request.Cookies.Parse( Request.Headers.Values['Cookie']);101 if Request.Headers.TryGetValue('Cookie', Value) then 102 Request.Cookies.Parse(Value); 100 103 101 104 // Load session variables … … 120 123 121 124 // Handle cookies 122 for I := 0 to Cookies.Count - 1do123 Headers.Add('Set-Cookie', Cookies.Keys[I] + '=' + Cookies.Items[I].Value);125 for Item in Cookies do 126 Headers.Add('Set-Cookie', Item.Key + '=' + Item.Value); 124 127 // + ';path=/;expires=' + RFC822DateTime(Now); 125 128 126 129 // Send headers 127 for I := 0 to Headers.Count - 1do begin130 for Item in Headers do begin 128 131 //WriteLn(Headers.Keys[I] + ': ' + Headers.Items[I].Value + #13#10); 129 SendString( Headers.Keys[I] + ': ' + Headers.Items[I].Value + #13#10);132 SendString(Item.Key + ': ' + Item.Value + #13#10); 130 133 end; 131 134 SendString(#13#10);
Note:
See TracChangeset
for help on using the changeset viewer.