Ignore:
Timestamp:
Jan 4, 2012, 2:27:19 PM (12 years ago)
Author:
chronos
Message:
  • Added: Support for handling POST values in HTTPServer.
  • Fixed: TCP server to start listening and wait for termination.
  • Added: ServerType of WebApp as CGI or TCP.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Network/CoolWeb/WebServer/UWebApp.pas

    r259 r311  
    77uses
    88  Classes, SysUtils, CustApp, SpecializedList, UWebPage, UHTTPSessionFile,
    9   UHTTPServer, UHTTPServerCGI;
     9  UHTTPServer;
    1010
    1111type
     12  THTTPServerType = (stCGI, stTCP);
     13
    1214  TRegistredPage = class
    1315    Name: string;
     
    2527  TWebApp = class(TCustomApplication)
    2628  private
     29    FOnBeforePageProduce: TOnProduceEvent;
    2730    FOnInitialize: TNotifyEvent;
     31    FServerType: THTTPServerType;
    2832    procedure DoRun; override;
    2933    function DumpExceptionCallStack(E: Exception): string;
    3034    procedure HTTPServerRequest(HandlerData: THTTPHandlerData);
     35    procedure SetServerType(AValue: THTTPServerType);
    3136  public
    3237    Pages: TRegistredPageList;
     
    3843    constructor Create(AOwner: TComponent); override;
    3944    destructor Destroy; override;
     45    property OnBeforePageProduce: TOnProduceEvent read FOnBeforePageProduce write FOnBeforePageProduce;
    4046    property OnInitialize: TNotifyEvent read FOnInitialize write FOnInitialize;
     47    property ServerType: THTTPServerType read FServerType write SetServerType;
    4148  end;
    4249
     
    4956
    5057implementation
     58
     59uses
     60  UHTTPServerCGI, UHTTPServerTCP;
    5161
    5262resourcestring
     
    125135    //Request.QueryParts[0] := 'uzivatel';
    126136    //Request.QueryParts[1] := 'prihlaseni';
     137    if Assigned(FOnBeforePageProduce) then
     138      FOnBeforePageProduce(HandlerData);
    127139
    128140    if Request.QueryParts.Count > 0 then PageName := Request.QueryParts[0]
     
    131143    if Assigned(Page) then begin
    132144      Page.Page.OnProduce(HandlerData);
    133     end else Response.Stream.WriteString(SPageNotFound);
    134   end;
     145    end else Response.Content.WriteString(SPageNotFound);
     146  end;
     147end;
     148
     149procedure TWebApp.SetServerType(AValue: THTTPServerType);
     150begin
     151  if FServerType = AValue then Exit;
     152  FServerType := AValue;
     153  HTTPServer.Free;
     154  case FServerType of
     155    stCGI: HTTPServer := THTTPServerCGI.Create(nil);
     156    stTCP: HTTPServer := THTTPServerTCP.Create(nil);
     157  end;
     158  HTTPServer.OnRequest := HTTPServerRequest;
    135159end;
    136160
     
    152176    hstdout := @stderr;
    153177    Writeln(hstdout^, 'An unhandled exception occurred: ' + E.Message + '<br>');
    154     WriteLn(hstdout^, StringReplace(DumpExceptionCallStack(E), LineEnding, '<br>', [rfReplaceAll]));
     178    WriteLn(hstdout^, DumpExceptionCallStack(E));
    155179  end;
    156180end;
Note: See TracChangeset for help on using the changeset viewer.