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ářů.
Location:
trunk/Components/CoolWeb
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Components/CoolWeb/Common/UHtmlClasses.pas

    r66 r67  
    155155    InputType: THtmlInputType;
    156156    Value: Variant;
     157    ItemName: string;
    157158    procedure Assign(Source: THtmlElement); override;
    158159    constructor Create;
     
    397398    Attributes.Add('type', InputTypeString);
    398399    Attributes.Add('value', Value);
    399     if Self.Name <> '' then
    400       Attributes.Add('name', Self.Name);
     400    if Self.ItemName <> '' then
     401      Attributes.Add('name', Self.ItemName);
    401402  end;
    402403end;
     
    407408  InputType := THtmlInput(Source).InputType;
    408409  Value := THtmlInput(Source).Value;
     410  ItemName := THtmlInput(Source).ItemName;
    409411end;
    410412
  • 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;
  • trunk/Components/CoolWeb/WebServer/UHTTPServerCGI.pas

    r61 r67  
    66
    77uses
    8   Classes, SysUtils, UHTTPServer, SpecializedList;
     8  Classes, SysUtils, UHTTPServer, SpecializedList, IOStream;
    99
    1010type
     
    5353  I: Integer;
    5454  HandlerData: THTTPHandlerData;
     55  InputStream: TIOStream;
     56  Line: string;
     57  Buffer: string;
     58  Count: Integer;
    5559begin
    5660  HandlerData := THTTPHandlerData.Create;
    5761  with HandlerData do try
     62    // Load headers
     63    try
     64      InputStream := TIOStream.Create(iosInput);
     65      SetLength(Buffer, 1000);
     66      repeat
     67        Count := InputStream.Read(Buffer[1], Length(Buffer));
     68        Request.Content.Write(Buffer[1], Count);
     69      until Count = 0;
     70    finally
     71      InputStream.Free;
     72    end;
     73
     74    //repeat
     75    //  ReadLn(Line);
     76    //until Line = '';
     77
     78    // Load data
     79    if Request.Headers.IndexOfName('Content-length') <> -1 then
     80    try
     81      InputStream := TIOStream.Create(iosInput);
     82      Request.Content.CopyFrom(InputStream, StrToInt(Request.Headers.Values['Content-length']));
     83    finally
     84      InputStream.Free;
     85    end;
     86
    5887    // Load environment variables
    5988    for I := 0 to GetEnvironmentVariableCount - 1 do begin
     
    80109      SessionStorage.Load(HandlerData);
    81110
    82     Response.Stream.Clear;
     111    // Load post data
     112    if EnvVars.IndexOfName('REQUEST_METHOD') <> -1 then begin
     113      if EnvVars.Values['REQUEST_METHOD'] = 'POST' then begin
     114        Request.Content.Position := 0;
     115        Buffer := Request.Content.ReadString;
     116        Request.Post.Parse(Buffer);
     117      end;
     118    end;
     119
     120    Response.Content.Clear;
    83121    Response.Headers.Values['Content-type'] := 'text/html';
    84122
     
    105143
    106144      // Emit page content
    107       Stream.Position := 0;
    108       WriteLn(Stream.ReadString);
     145      Content.Position := 0;
     146      WriteLn(Content.ReadString);
    109147    end;
    110148  finally
     
    118156begin
    119157  inherited;
    120   with HandlerData, Response.Stream do begin
     158  with HandlerData, Response.Content do begin
    121159    WriteString('<h5>' + SEnvironmentVariables + '</h5>');
    122160    WriteString('<table border="1">');
  • trunk/Components/CoolWeb/WebServer/UHTTPServerTCP.pas

    r61 r67  
    8888      SessionStorage.Load(HandlerData);
    8989
    90     Response.Stream.Clear;
     90    Response.Content.Clear;
    9191    Response.Headers.Values['Content-Type'] := 'text/html';
    9292
     
    100100    with Response do begin
    101101      SendString('HTTP/1.0 200 OK'#13#10);
    102       Headers.Values['Content-Length'] := IntToStr(Stream.Size);
     102      Headers.Values['Content-Length'] := IntToStr(Content.Size);
    103103      Headers.Values['Connection'] := 'close';
    104104      Headers.Values['Date'] := RFC822DateTime(Now);
     
    115115      end;
    116116      SendString(#13#10);
    117       SendBuffer(Stream.Memory, Stream.Size);
     117      SendBuffer(Content.Memory, Content.Size);
    118118      SendString(#13#10);
    119119    end;
  • trunk/Components/CoolWeb/WebServer/UWebApp.pas

    r61 r67  
    131131    if Assigned(Page) then begin
    132132      Page.Page.OnProduce(HandlerData);
    133     end else Response.Stream.WriteString(SPageNotFound);
     133    end else Response.Content.WriteString(SPageNotFound);
    134134  end;
    135135end;
Note: See TracChangeset for help on using the changeset viewer.