unit HttpData;

{==========================================================}
{                                                          }
{  unit HttpData                       12/11/2002          }
{                                                          }
{  Data HTTP serveru                                       }
{                                                          }
{                                                          }
{  (C)2002, SofCon, Stresovicka 49, 160 00 Praha 6         }
{           Petr Cernin                                    }
{                                                          }
{==========================================================}

interface

{$I SETS.INC} { Nastaveni podmineneho prekladu }

uses
  Http;

  {-------------------------------
  { GetDocument
  {---
  { Funkce vraci ukazatel na tabulku dokumentu zpracovavanych
  { metodou GET
  {---
  { Funkci vola jednotka HttpSvr
  }

  function  GetDocument: PHttpDispatchItem;



implementation

uses
  Strings,
  Kernel;


  {-------------------------------
  { GetDocRoot
  {---
  { Vyplneni odpovedi na dotaz GET /
  {---
  }

  function GetDocRoot( ASession: PHttpSession; APath: PChar;
    AIndex: Integer ): Boolean; far;
  begin
    with ASession^.Response do
    begin
      StatusCode := HTE_OK;

      BeginEntity;
      with Content do
      begin
        Append( '<HTML>' );
        Append( '<HEAD><META HTTP-EQUIV="Refresh" CONTENT="1"></HEAD>' );

        Append( '<BODY><B>WWW Server</B><BR>' );
        AppendTime( HttpGetTime );
        Append( '<P>' );

        Append( '<TABLE BORDER=1><TR><TD>Path</TD><TD>' );
        Append( ASession^.Request.Path );
        Append( '</TD></TR><TR><TD>Version</TD><TD>' );
        Append( ASession^.Request.Version );
        Append( '</TD></TR><TR><TD>Query</TD><TD>' );
        Append( ASession^.Request.Query );
        Append( '</TD></TR><TR><TD>Accept</TD><TD>' );
        Append( ASession^.Request.Accept );
        Append( '</TD></TR><TR><TD>Referer</TD><TD>' );
        Append( ASession^.Request.Referer );
        Append( '</TD></TR><TR><TD>UserAgent</TD><TD>' );
        Append( ASession^.Request.UserAgent );
        Append( '</TD></TR></TABLE>' );

        Append( '<P>Odkaz na stranku <A HREF="/page1.html">page1.html</A>' );
        Append( '</BODY></HTML>' );
      end;

      EndEntity;
    end;

    GetDocRoot := True;
  end;


  {-------------------------------
  { GetDocPage1
  {---
  { Vyplneni odpovedi na dotaz GET /page1.html
  {---
  }

  function GetDocPage1( ASession: PHttpSession; APath: PChar;
    AIndex: Integer ): Boolean; far;
  begin
    with ASession^.Response do
    begin
      StatusCode := HTE_OK;

      BeginEntity;
      with Content do
      begin
        Append( '<HTML>' );
        Append( '<HEAD></HEAD>' );

        Append( '<BODY><B>WWW Server</B><BR>' );
        AppendTime( HttpGetTime );
        Append( '<P>' );

        Append( '<TABLE BORDER=1><TR><TD>Path</TD><TD>' );
        Append( ASession^.Request.Path );
        Append( '</TD></TR><TR><TD>Version</TD><TD>' );
        Append( ASession^.Request.Version );
        Append( '</TD></TR><TR><TD>Query</TD><TD>' );
        Append( ASession^.Request.Query );
        Append( '</TD></TR><TR><TD>Accept</TD><TD>' );
        Append( ASession^.Request.Accept );
{       Append( '</TD></TR><TR><TD>Host</TD><TD>' );
        Append( ASession^.Request.Host );}
        Append( '</TD></TR><TR><TD>Referer</TD><TD>' );
        Append( ASession^.Request.Referer );
        Append( '</TD></TR><TR><TD>UserAgent</TD><TD>' );
        Append( ASession^.Request.UserAgent );
        Append( '</TD></TR></TABLE></BODY></HTML>' );
      end;


      EndEntity;
    end;

    GetDocPage1 := True;
  end;



  {-------------------------------
  { GetDocument
  {---
  { Funkce vraci ukazatel na tabulku dokumentu zpracovavanych
  { metodou GET
  {---
  { Funkci vola jednotka HttpSvr
  }

  function GetDocument: PHttpDispatchItem;
  const
    Document: array[0..2] of THttpDispatchItem =
    (
      ( Segment: '';             Dispatcher: GetDocRoot  ),
      ( Segment: 'page1.html';   Dispatcher: GetDocPage1 ),
      ( Segment: nil;            Dispatcher: nil )
    );

  begin
    GetDocument := @Document;
  end;


end.
