private
procedure RunWebModuleClass(AThread: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
protected
FWebModuleClass: TComponentClass;
//
procedure DoCommandGet(AThread: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo); override;
procedure DoCommandOther(AThread: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo); override;
procedure InitComponent; override;
public
procedure RegisterWebModuleClass(AClass: TComponentClass);
end;
procedure TIdHTTPWebBrokerBridge.DoCommandGet(AThread: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
if FWebModuleClass <> nil then begin
// FWebModuleClass, RegisterWebModuleClass supported for backward compatability
RunWebModuleClass(AThread, ARequestInfo, AResponseInfo)
end else
begin
{$IFDEF HAS_CLASSVARS}
TIdHTTPWebBrokerBridgeRequestHandler.FWebRequestHandler.Run(AThread, ARequestInfo, AResponseInfo);
{$ELSE}
IndyWebRequestHandler.Run(AThread, ARequestInfo, AResponseInfo);
{$ENDIF}
end;
end;
TIdHTTPWebBrokerBridgeRequestHandler = class(TWebRequestHandler)
{$IFDEF HAS_CLASSVARS}
private
class var FWebRequestHandler: TIdHTTPWebBrokerBridgeRequestHandler;
{$ENDIF}
public
constructor Create(AOwner: TComponent); override;
{$IFDEF HAS_CLASSVARS}
{$IFDEF HAS_CLASSDESTRUCTOR}
class destructor Destroy;
{$ENDIF}
{$ENDIF}
destructor Destroy; override;
procedure Run(AThread: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
end;
procedure TIdHTTPWebBrokerBridgeRequestHandler.Run(AThread: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
LRequest: TIdHTTPAppRequest;
LResponse: TIdHTTPAppResponse;
begin
try
LRequest := TIdHTTPAppRequest.Create(AThread, ARequestInfo, AResponseInfo);
try
LResponse := TIdHTTPAppResponse.Create(LRequest, AThread, ARequestInfo, AResponseInfo);
try
// WebBroker will free it and we cannot change this behaviour
AResponseInfo.FreeContentStream := False;
HandleRequest(LRequest, LResponse);
finally
FreeAndNil(LResponse);
end;
finally
FreeAndNil(LRequest);
end;
except
// Let Indy handle this exception
raise;
end;
end;