unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, IdCustomHTTPServer,
IdHTTPServer, IdTCPConnection, IdTCPClient, IdHTTP;
type
TForm1 =
class(TForm)
IdHTTPServer1: TIdHTTPServer;
IdHTTP1: TIdHTTP;
procedure IdHTTP1ServerCreatePostStream(ASender: TIdPeerThread);
procedure IdHTTPServer1CommandGet(AThread: TIdPeerThread; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// event handler for the OnCreatePostStream event...
procedure TForm1.IdHTTP1ServerCreatePostStream(ASender: TIdPeerThread);
var VPostStream: TStream;
begin
// creating our own stream so that TIdHTTPServer does not automatically
// free the PostStream before the OnCommandGet event is triggered
VPostStream := TMemoryStream.Create;
end;
// event handler for the On CommandGet event...
procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
LHTTP: TIdHTTP;
LURL:
String;
LMethod: TIdHTTPMethod;
LSource, LDest: TStream;
begin
LSource :=
nil;
LDest :=
nil;
if ARequestInfo.Command = '
GET'
then begin
LMethod := hmGet;
end else if ARequestInfo.Command = '
POST'
then begin
LMethod := hmPost;
end else if ARequestInfo.Command = '
HEAD'
then begin
LMethod := hmHead;
end else begin
AResponseInfo.ResponseNo := 501;
// not implemented
Exit;
end;
if LMethod <> hmHead
then begin
AResponseInfo.ContentStream := TMemoryStream.Create;
if LMethod = hmPost
then LSource := ARequestInfo.PostStream;
LDest := AResponseInfo.ContentStream;
end;
LURL := '
http://' + ARequestInfo.Document;
if Length(ARequest.QueryParams) > 0
then begin
LURL := LURL + '
?' + ARequest.QueryParams;
end;
LHTTP := TIdHTTP.Create(
nil);
try
try
LHTTP.DoRequest(LMethod, LURL, LSource, LDest);
finally
AResponseInfo.ResponseNo := LHTTP.Response.ResponseCode;
AResponseInfo.ResponseText := LHTTP.Response.ResponseText;
AResponseInfo.RawHeaders.Assign(LHTTP.Response.RawHeaders);
// copy over anything else that is needed...
LHTTP.Free;
end;
except end;
end;
end.