Changeset 138 for trunk/Packages/CoolWeb/WebServer/UHTTPServer.pas
- Timestamp:
- Sep 9, 2022, 8:20:25 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/CoolWeb/WebServer/UHTTPServer.pas
r137 r138 4 4 5 5 uses 6 Classes, SysUtils, UCommon, UMemoryStreamEx, UMIMEType, 7 Synautil, SpecializedList, SpecializedDictionary, Syncobjs;6 Classes, SysUtils, UCommon, UMemoryStreamEx, UMIMEType, Synautil, Syncobjs, 7 Generics.Collections, UGenerics; 8 8 9 9 type … … 75 75 { TRequestHandlerList } 76 76 77 TRequestHandlerList = class(T ListObject)77 TRequestHandlerList = class(TObjectList<TRequestHandler>) 78 78 procedure Add(AName: string; AHandler: TRequestEvent); 79 79 function IndexOfName(AName: string): TRequestHandler; … … 131 131 var 132 132 I: Integer; 133 Item: TPair<string, string>; 133 134 begin 134 135 with HandlerData, Response.Content do begin … … 145 146 146 147 WriteString('<h5>Request HTTP headers</h5>'); 147 for I := 0 to Request.Headers.Count - 1 do begin; 148 with Request.Headers.Items[I] do 149 WriteString(Key + ': ' + Value + '<br/>'); 148 for Item in Request.Headers do begin; 149 WriteString(Item.Key + ': ' + Item.Value + '<br/>'); 150 150 end; 151 151 152 152 WriteString('<h5>Request HTTP GET</h5>'); 153 for I := 0 to Request.Query.Count - 1 do begin 154 with Request.Query.Items[I] do 155 WriteString(Key + ': ' + Value + '<br/>'); 153 for Item in Request.Query do begin 154 WriteString(Item.Key + ': ' + Item.Value + '<br/>'); 156 155 end; 157 156 158 157 WriteString('<h5>Request HTTP cookies</h5>'); 159 158 for I := 0 to Request.Cookies.Count - 1 do begin 160 with Request.Cookies.Items[I] do 161 WriteString(Key + ': ' + Value + '<br/>'); 159 WriteString(Item.Key + ': ' + Item.Value + '<br/>'); 162 160 end; 163 161 … … 170 168 171 169 WriteString('<h5>Request HTTP POST</h5>'); 172 for I := 0 to Request.Post.Count - 1 do begin 173 with Request.Post.Items[I] do 174 WriteString(Key + ': ' + Value + '<br/>'); 170 for Item in Request.Post do begin 171 WriteString(Item.Key + ': ' + Item.Value + '<br/>'); 175 172 end; 176 173 … … 181 178 WriteString('<h5>Response HTTP headers</h5>'); 182 179 with Response.Content do 183 for I := 0 to Response.Headers.Count - 1 do begin 184 with Response.Headers.Items[I] do 185 WriteString(Key + ': ' + Value + '<br/>'); 180 for Item in Response.Headers do begin 181 WriteString(Item.Key + ': ' + Item.Value + '<br/>'); 186 182 end; 187 183 188 184 WriteString('<h5>Response HTTP cookies</h5>'); 189 for I := 0 to Response.Cookies.Count - 1 do begin; 190 with Response.Cookies.Items[I] do 191 WriteString(Key + ': ' + Value + '<br/>'); 185 for Item in Response.Cookies do begin; 186 WriteString(Item.Key + ': ' + Item.Value + '<br/>'); 192 187 end; 193 188 end; … … 197 192 begin 198 193 with HandlerData, Response.Content do begin 199 WriteString('<html><body>' + Format(SPageNotFound, [ Request.Path.Implode('/', StrToStr)]) + '</body></html>');194 WriteString('<html><body>' + Format(SPageNotFound, [Implode('/', Request.Path)]) + '</body></html>'); 200 195 end; 201 196 end; … … 218 213 begin 219 214 with HandlerData do begin 220 FileName := DocumentRoot + DirectorySeparator + Request.Path.Implode('/', StrToStr);215 FileName := DocumentRoot + DirectorySeparator + Implode('/', Request.Path); 221 216 if FileExists(FileName) then begin 222 Response.Headers. Values['Content-Type'] := GetMIMEType(Copy(ExtractFileExt(FileName), 2, 255));217 Response.Headers.Items['Content-Type'] := GetMIMEType(Copy(ExtractFileExt(FileName), 2, 255)); 223 218 try 224 219 BinaryFile := TFileStream.Create(FileName, fmOpenRead); … … 230 225 with Response.Content do begin 231 226 //WriteLn(Format(SFileNotFound, [Request.Path.Implode('/', StrToStr)])); 232 WriteString('<html><body>' + Format(SFileNotFound, [ Request.Path.Implode('/', StrToStr)]) + '</body></html>');227 WriteString('<html><body>' + Format(SFileNotFound, [Implode('/', Request.Path)]) + '</body></html>'); 233 228 end; 234 229 end; … … 357 352 Pair := TListString.Create; 358 353 Clear; 359 Parts.Explode( Text, '&', StrToStr);354 Parts.Explode('&', Text); 360 355 for I := 0 to Parts.Count - 1 do begin 361 Pair.Explode( Parts[I], '=', StrToStr);356 Pair.Explode('=', Parts[I]); 362 357 if Pair.Count >= 2 then 363 358 Add(Pair[0], Pair[1]); … … 371 366 function TQueryParameterList.Syntetize: string; 372 367 var 373 I : Integer;368 Item: TPair<string, string>; 374 369 begin 375 370 Result := ''; 376 for I := 0 to Count - 1do377 Result := Result + '&' + Keys[I] + '=' + Items[I].Value;371 for Item in Self do 372 Result := Result + '&' + Item.Key + '=' + Item.Value; 378 373 Result := Copy(Result, 6, Length(Result)); 379 374 end; … … 391 386 Pair := TListString.Create; 392 387 Clear; 393 Parts.Explode( Text, ';', StrToStr);388 Parts.Explode(';', Text); 394 389 for I := 0 to Parts.Count - 1 do begin 395 Pair.Explode( Parts[I], '=', StrToStr);390 Pair.Explode('=', Parts[I]); 396 391 if Pair.Count >= 2 then 397 392 Add(Trim(Pair[0]), Trim(Pair[1])); … … 405 400 function TCookieList.Syntetize: string; 406 401 var 407 I : Integer;402 Item: TPair<string, string>; 408 403 begin 409 404 Result := ''; 410 for I := 0 to Count - 1do411 Result := Result + '; ' + Keys[I] + '=' + Items[I].Value;405 for Item in Self do 406 Result := Result + '; ' + Item.Key + '=' + Item.Value; 412 407 Result := Copy(Result, 2, Length(Result)); 413 408 end;
Note:
See TracChangeset
for help on using the changeset viewer.