summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fcl-web/src/base/webutil.pp
blob: 313a2283a698281eaf16cab169a5d543eed98499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{
    $Id: header,v 1.1 2000/07/13 06:33:45 michael Exp $
    This file is part of the Free Component Library (FCL)
    Copyright (c) 1999-2000 by the Free Pascal development team

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
unit webutil;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, httpdefs;

procedure DumpRequest (ARequest : TRequest; Dump : TStrings; Environment : Boolean = False);

implementation



procedure DumpRequest (ARequest : TRequest; Dump : TStrings; Environment : Boolean = False);

  Procedure AddNV(Const N,V : String);
  
  begin
    Dump.Add('<TR><TD>'+N+'</TD><TD>'+V+'</TD></TR>');
  end;

Var
  I,J   : integer;
  N,V : String;
begin
  With ARequest, Dump do
    begin
    // All possible headers
    Add('<H1>All possible request headers:</H1>');
    Add('<TABLE BORDER="1"><TR><TD>Header</TD><TD>Value</TD></TR>');
    For I:=1 to NoHTTPFields do
      begin
      AddNV(HTTPFieldNames[i],GetFieldByName(HTTPFieldNames[i]));
      end;
    Add('</TABLE><P>');

    // Actually sent headers
    Add('<H1>Actually sent request headers:</H1>');
    Add('<TABLE BORDER="1"><TR><TD>Header</TD><TD>Value</TD></TR>');
    For I:=0 to FieldCount-1 do
      AddNV(FieldNames[I],FieldValues[I]);
    Add('</TABLE><P>');

    // Actually sent headers, as text
    Add('<H1>Actually sent request headers as text:</H1>');
    For I:=0 to FieldCount-1 do
      Add(Fields[I]+'<BR>');
      
    // Additional headers
    Add('<H1>Additional headers:</H1>');
    Add('<TABLE BORDER="1"><TR><TD>Header</TD><TD>Value</TD></TR>');
    AddNV('PathInfo',PathInfo);
    AddNV('PathTranslated',PathTranslated);
    AddNV('RemoteAddress',RemoteAddress);
    AddNV('RemoteHost',RemoteHost);
    AddNV('ScriptName',ScriptName);
    AddNV('ServerPort',IntToStr(ServerPort));
    AddNV('Method',Method);
    AddNV('URL',URL);
    AddNV('Query',Query);
    AddNV('Host',Host);
    AddNV('Content',Content);
    Add('</TABLE><P>');
    // Additional headers
    If (QueryFields.Count>0) then
      begin
      Add('<H1>Request variables: ('+IntToStr(QueryFields.Count)+') </H1>');
      Add('<TABLE BORDER="1"><TR><TD>Name</TD><TD>Value</TD></TR>');
      For I:=0 to QueryFields.Count-1 do
        begin
        QueryFields.GetNameValue(i,N,V);
        AddNV(N,V);
        end;
      Add('</TABLE><P>');
      end;
    If (ContentFields.Count>0) then
      begin
      Add('<H1>Form post variables: ('+IntToStr(ContentFields.Count)+') </H1>');
      Add('<TABLE BORDER="1"><TR><TD>Name</TD><TD>Value</TD></TR>');
      For I:=0 to ContentFields.Count-1 do
        begin
        ContentFields.GetNameValue(i,N,V);
        AddNV(N,V);
        end;
      Add('</TABLE><P>');
      end;
    If Environment then
      begin
      Add('<H1>Environment variables: ('+IntToStr(GetEnvironmentVariableCount)+') </H1>');
      Add('<TABLE BORDER="1"><TR><TD>Name</TD><TD>Value</TD></TR>');
      For I:=1 to GetEnvironmentVariableCount do
        begin
        V:=GetEnvironmentString(i);
        j:=Pos('=',V);
        If (J>0) then
          begin
          N:=Copy(V,1,J-1);
          system.Delete(V,1,J);
          AddNV(N,V);
          end;
        end;
      Add('</TABLE><P>');
      end;
    If (Files.Count>0) then
      begin
      Add('<H1>Uploaded files: ('+IntToStr(Files.Count)+') </H1>');
      Add('<TABLE BORDER="1">');
      Add('<TR><TD>Name</TD><TD>FileName</TD><TD>Size</TD>');
      Add('<TD>Temp FileName</TD><TD>Disposition</TD><TD>Content-Type</TD><TD>Description</TD></TR>');
      For I:=0 to Files.Count-1 do
        With Files[i] do
          begin
          Add('<TR><TD>'+FieldName+'</TD><TD>'+FileName+'</TD>');
          Add('<TD>'+IntToStr(Size)+'</TD><TD>'+LocalFileName+'</TD>');
          Add('<TD>'+Disposition+'</TD><TD>'+ContentType+'</TD><TD>'+Description+'</TD></TR>');
          end;
      Add('</TABLE><P>');
      end;
    end;
end;

end.