Ignore:
Timestamp:
Dec 25, 2011, 9:40:28 PM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Přidáno analyzování HTTP POST informací.
  • Upraveno: Příprava pro zpracování hodnot z objektů HTML formulářů.
File:
1 edited

Legend:

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

    r61 r67  
    2828
    2929  THTTPRequest = class
     30    ContentType: string;
     31    Content: TMemoryStreamEx;
    3032    Query: TQueryParameterList;
    3133    QueryParts: TListString;
     
    3436    Headers: TStringList;
    3537    Cookies: TCookieList;
     38    Post: TQueryParameterList;
    3639    constructor Create;
    3740    destructor Destroy; override;
     
    4245  THTTPResponse = class
    4346    ContentType: string;
    44     Stream: TMemoryStreamEx;
     47    Content: TMemoryStreamEx;
    4548    Headers: TStringList;
    4649    Cookies: TCookieList;
     
    126129  I: Integer;
    127130begin
    128   with HandlerData, Response.Stream do begin
     131  with HandlerData, Response.Content do begin
    129132    //Response.Cookies.Values['Test'] := 'Halo';
    130133    //Response.Cookies.Values['Test2'] := 'Halo2';
     
    134137
    135138    WriteString('<a href="?ServerInfo">Refresh</a>');
     139
     140    WriteString('<h5>Request HTTP content:</h5>');
     141    WriteStream(Request.Content, Request.Content.Size);
    136142
    137143    WriteString('<h5>Request HTTP headers</h5>');
     
    151157    end;
    152158
     159    WriteString('<h5>Request HTTP POST</h5>');
     160    for I := 0 to Request.Post.Count - 1 do begin;
     161      WriteString(Request.Post.Strings[I] + '<br/>');
     162    end;
     163
     164
     165    WriteString('<h5>Response HTTP content:</h5>');
     166    WriteStream(Response.Content, Response.Content.Size);
     167
    153168    WriteString('<h5>Response HTTP headers</h5>');
    154     with Response.Stream do
     169    with Response.Content do
    155170    for I := 0 to Response.Headers.Count - 1 do begin;
    156171      WriteString(Response.Headers.Strings[I] + '<br/>');
     
    166181procedure THTTPServer.ErrorResponse(HandlerData: THTTPHandlerData);
    167182begin
    168   with HandlerData, Response.Stream do begin
     183  with HandlerData, Response.Content do begin
    169184    WriteString('<html><body>' + Format(SPageNotFound, [Request.Path]) + '</body></html>');
    170185  end;
     
    193208      Response.Headers.Values['Content-Type'] := GetMIMEType(Copy(ExtractFileExt(FileName), 2, 255));
    194209      BinaryFile := TFileStream.Create(FileName, fmOpenRead);
    195       Response.Stream.WriteStream(BinaryFile, BinaryFile.Size);
     210      Response.Content.WriteStream(BinaryFile, BinaryFile.Size);
    196211      BinaryFile.Destroy;
    197212    end else
    198     with Response.Stream do begin
     213    with Response.Content do begin
    199214      WriteLn(Format(SFileNotFound, [Request.Path]));
    200215      WriteString('<html><body>' + Format(SFileNotFound, [Request.Path]) + '</body></html>');
     
    219234constructor THTTPResponse.Create;
    220235begin
    221   Stream := TMemoryStreamEx.Create;
     236  Content := TMemoryStreamEx.Create;
    222237  Cookies := TCookieList.Create;
    223238  Headers := TStringList.Create;
     
    226241destructor THTTPResponse.Destroy;
    227242begin
    228   Stream.Free;
     243  Content.Free;
    229244  Headers.Free;
    230245  Cookies.Free;
     
    255270constructor THTTPRequest.Create;
    256271begin
     272  Post := TQueryParameterList.Create;
    257273  Query := TQueryParameterList.Create;
    258274  QueryParts := TListString.Create;
    259275  Headers := TStringList.Create;
    260276  Cookies := TCookieList.Create;
     277  Content := TMemoryStreamEx.Create;
    261278end;
    262279
    263280destructor THTTPRequest.Destroy;
    264281begin
     282  Content.Free;
     283  Post.Free;
    265284  Query.Free;
    266285  QueryParts.Free;
Note: See TracChangeset for help on using the changeset viewer.