Ignore:
Timestamp:
Sep 9, 2022, 8:20:25 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Removed TemplateGenerics package. Generics usage replaced by standard Generics.Collections.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CoolWeb/WebServer/UHTTPServer.pas

    r137 r138  
    44
    55uses
    6   Classes, SysUtils, UCommon, UMemoryStreamEx, UMIMEType,
    7   Synautil, SpecializedList, SpecializedDictionary, Syncobjs;
     6  Classes, SysUtils, UCommon, UMemoryStreamEx, UMIMEType, Synautil, Syncobjs,
     7  Generics.Collections, UGenerics;
    88
    99type
     
    7575  { TRequestHandlerList }
    7676
    77   TRequestHandlerList = class(TListObject)
     77  TRequestHandlerList = class(TObjectList<TRequestHandler>)
    7878    procedure Add(AName: string; AHandler: TRequestEvent);
    7979    function IndexOfName(AName: string): TRequestHandler;
     
    131131var
    132132  I: Integer;
     133  Item: TPair<string, string>;
    133134begin
    134135  with HandlerData, Response.Content do begin
     
    145146
    146147    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/>');
    150150    end;
    151151
    152152    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/>');
    156155    end;
    157156
    158157    WriteString('<h5>Request HTTP cookies</h5>');
    159158    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/>');
    162160    end;
    163161
     
    170168
    171169    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/>');
    175172    end;
    176173
     
    181178    WriteString('<h5>Response HTTP headers</h5>');
    182179    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/>');
    186182    end;
    187183
    188184    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/>');
    192187    end;
    193188  end;
     
    197192begin
    198193  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>');
    200195  end;
    201196end;
     
    218213begin
    219214  with HandlerData do begin
    220     FileName := DocumentRoot + DirectorySeparator + Request.Path.Implode('/', StrToStr);
     215    FileName := DocumentRoot + DirectorySeparator + Implode('/', Request.Path);
    221216    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));
    223218      try
    224219        BinaryFile := TFileStream.Create(FileName, fmOpenRead);
     
    230225    with Response.Content do begin
    231226      //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>');
    233228    end;
    234229  end;
     
    357352    Pair := TListString.Create;
    358353    Clear;
    359     Parts.Explode(Text, '&', StrToStr);
     354    Parts.Explode('&', Text);
    360355    for I := 0 to Parts.Count - 1 do begin
    361       Pair.Explode(Parts[I], '=', StrToStr);
     356      Pair.Explode('=', Parts[I]);
    362357      if Pair.Count >= 2 then
    363358        Add(Pair[0], Pair[1]);
     
    371366function TQueryParameterList.Syntetize: string;
    372367var
    373   I: Integer;
     368  Item: TPair<string, string>;
    374369begin
    375370  Result := '';
    376   for I := 0 to Count - 1 do
    377     Result := Result + '&amp;' + Keys[I] + '=' + Items[I].Value;
     371  for Item in Self do
     372    Result := Result + '&amp;' + Item.Key + '=' + Item.Value;
    378373  Result := Copy(Result, 6, Length(Result));
    379374end;
     
    391386    Pair := TListString.Create;
    392387    Clear;
    393     Parts.Explode(Text, ';', StrToStr);
     388    Parts.Explode(';', Text);
    394389    for I := 0 to Parts.Count - 1 do begin
    395       Pair.Explode(Parts[I], '=', StrToStr);
     390      Pair.Explode('=', Parts[I]);
    396391      if Pair.Count >= 2 then
    397392        Add(Trim(Pair[0]), Trim(Pair[1]));
     
    405400function TCookieList.Syntetize: string;
    406401var
    407   I: Integer;
     402  Item: TPair<string, string>;
    408403begin
    409404  Result := '';
    410   for I := 0 to Count - 1 do
    411     Result := Result + '; ' + Keys[I] + '=' + Items[I].Value;
     405  for Item in Self do
     406    Result := Result + '; ' + Item.Key + '=' + Item.Value;
    412407  Result := Copy(Result, 2, Length(Result));
    413408end;
Note: See TracChangeset for help on using the changeset viewer.