Changeset 139 for trunk/Packages


Ignore:
Timestamp:
Sep 9, 2022, 9:41:42 PM (22 months ago)
Author:
chronos
Message:
  • Fixed: Better handle invalid not found pages including correct HTTP code.
Location:
trunk/Packages
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UFormAbout.pas

    r137 r139  
    2020    PanelButtons: TPanel;
    2121    procedure ButtonHomePageClick(Sender: TObject);
    22     procedure FormCreate(Sender: TObject);
    2322    procedure FormShow(Sender: TObject);
    24   private
    25     { private declarations }
    2623  public
    2724    AboutDialog: TObject; //TAboutDialog
     
    7774end;
    7875
    79 procedure TFormAbout.FormCreate(Sender: TObject);
    80 begin
    81 end;
    82 
    8376end.
    8477
  • trunk/Packages/Common/UGenerics.pas

    r138 r139  
    4343  for I := 0 to Count - 1 do begin
    4444    Result := Result + Items[I];
    45     if I > 0 then Result := Result + Separator;
     45    if I < Count - 1 then Result := Result + Separator;
    4646  end;
    4747end;
  • trunk/Packages/CoolWeb/WebServer/UHTTPServer.pas

    r138 r139  
    4343
    4444  THTTPResponse = class
     45    StatusCode: string;
    4546    ContentType: string;
    4647    Content: TMemoryStreamEx;
     
    123124  SPageNotFound = 'Page %s not found.';
    124125
     126const
     127  StatusCodeNotFound = '404 Not Found';
     128
    125129
    126130implementation
     
    134138begin
    135139  with HandlerData, Response.Content do begin
    136     //Response.Cookies.Values['Test'] := 'Halo';
    137     //Response.Cookies.Values['Test2'] := 'Halo2';
    138 
    139     //HTTPServer.SessionHandler.Variables.Values['Session1'] := 'Value1';
    140     //HTTPServer.SessionHandler.Variables.Values['Session2'] := 'Value2';
    141 
    142140    WriteString('<a href="?ServerInfo">Refresh</a>');
    143141
     
    192190begin
    193191  with HandlerData, Response.Content do begin
     192    Response.StatusCode := StatusCodeNotFound;
    194193    WriteString('<html><body>' + Format(SPageNotFound, [Implode('/', Request.Path)]) + '</body></html>');
    195194  end;
     
    224223    end else
    225224    with Response.Content do begin
    226       //WriteLn(Format(SFileNotFound, [Request.Path.Implode('/', StrToStr)]));
     225      Response.StatusCode := StatusCodeNotFound;
    227226      WriteString('<html><body>' + Format(SFileNotFound, [Implode('/', Request.Path)]) + '</body></html>');
    228227    end;
     
    248247procedure THTTPResponse.Assign(Source: THTTPResponse);
    249248begin
     249  StatusCode := Source.StatusCode;
    250250  Content.Assign(Source.Content);
    251251  ContentType := Source.ContentType;
     
    263263constructor THTTPResponse.Create;
    264264begin
     265  StatusCode := '200 OK';
    265266  Content := TMemoryStreamEx.Create;
    266267  Cookies := TCookieList.Create;
     
    291292begin
    292293  I := 0;
    293   while (I < Count) and (TRequestHandler(Items[I]).Name <> AName) do Inc(I);
    294   if I < Count then Result := TRequestHandler(Items[I]) else Result := nil;
     294  while (I < Count) and (Items[I].Name <> AName) do Inc(I);
     295  if I < Count then Result := Items[I]
     296    else Result := nil;
    295297end;
    296298
  • trunk/Packages/CoolWeb/WebServer/UHTTPServerTCP.pas

    r138 r139  
    117117
    118118    with Response do begin
    119       SendString('HTTP/1.0 200 OK'#13#10);
     119      SendString('HTTP/1.0 ' + StatusCode + #13#10);
    120120      Headers.Add('Content-Length', IntToStr(Content.Size));
    121121      Headers.Add('Connection', 'close');
  • trunk/Packages/CoolWeb/WebServer/UTurboPowerForm.pas

    r137 r139  
    2424    procedure AShowSourceExecute(Sender: TObject);
    2525    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    26   private
    27     { private declarations }
    2826  public
    2927    HtmlSource: string;
  • trunk/Packages/PersistentData/Demo/UFormMain.pas

    r137 r139  
    2020    procedure ComboBox1Change(Sender: TObject);
    2121    procedure FormShow(Sender: TObject);
    22   private
    23     { private declarations }
    2422  public
    2523    Client: TPDClient;
Note: See TracChangeset for help on using the changeset viewer.