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/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">');
Note: See TracChangeset for help on using the changeset viewer.