|
@@ -106,6 +106,8 @@ Type
|
|
FOnLog : TLogEvent;
|
|
FOnLog : TLogEvent;
|
|
FPreferModuleName : Boolean;
|
|
FPreferModuleName : Boolean;
|
|
protected
|
|
protected
|
|
|
|
+ Class Procedure DoError(Msg : String; AStatusCode : Integer = 0; AStatusText : String = '');
|
|
|
|
+ Class Procedure DoError(Fmt : String; Const Args : Array of const;AStatusCode : Integer = 0; AStatusText : String = '');
|
|
procedure Terminate; virtual;
|
|
procedure Terminate; virtual;
|
|
Function GetModuleName(Arequest : TRequest) : string;
|
|
Function GetModuleName(Arequest : TRequest) : string;
|
|
function WaitForRequest(out ARequest : TRequest; out AResponse : TResponse) : boolean; virtual; abstract;
|
|
function WaitForRequest(out ARequest : TRequest; out AResponse : TResponse) : boolean; virtual; abstract;
|
|
@@ -205,7 +207,7 @@ Type
|
|
Property PreferModuleName : Boolean Read GetPreferModuleName Write SetPreferModuleName;
|
|
Property PreferModuleName : Boolean Read GetPreferModuleName Write SetPreferModuleName;
|
|
end;
|
|
end;
|
|
|
|
|
|
- EFPWebError = Class(Exception);
|
|
|
|
|
|
+ EFPWebError = Class(EFPHTTPError);
|
|
|
|
|
|
procedure ExceptionToHTML(S: TStrings; const E: Exception; const Title, Email, Administrator: string);
|
|
procedure ExceptionToHTML(S: TStrings; const E: Exception; const Title, Email, Administrator: string);
|
|
|
|
|
|
@@ -254,7 +256,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWebHandler.Run;
|
|
|
|
|
|
+Procedure TWebHandler.Run;
|
|
var ARequest : TRequest;
|
|
var ARequest : TRequest;
|
|
AResponse : TResponse;
|
|
AResponse : TResponse;
|
|
begin
|
|
begin
|
|
@@ -267,16 +269,29 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWebHandler.Log(EventType: TEventType; const Msg: String);
|
|
|
|
|
|
+Procedure TWebHandler.Log(EventType: TEventType; Const Msg: String);
|
|
begin
|
|
begin
|
|
If Assigned(FOnLog) then
|
|
If Assigned(FOnLog) then
|
|
FOnLog(EventType,Msg);
|
|
FOnLog(EventType,Msg);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TWebHandler.ShowRequestException(R: TResponse; E: Exception);
|
|
procedure TWebHandler.ShowRequestException(R: TResponse; E: Exception);
|
|
|
|
+
|
|
|
|
+ Function GetStatusCode : integer;
|
|
|
|
+
|
|
|
|
+ begin
|
|
|
|
+ if (E is EHTTP) then
|
|
|
|
+ Result:=EHTTP(E).StatusCode
|
|
|
|
+ else
|
|
|
|
+ Result:=E.HelpContext;
|
|
|
|
+ if (Result=0) then
|
|
|
|
+ Result:=500;
|
|
|
|
+ end;
|
|
|
|
+
|
|
Var
|
|
Var
|
|
- S : TStrings;
|
|
|
|
- handled: boolean;
|
|
|
|
|
|
+ S : TStrings;
|
|
|
|
+ handled: boolean;
|
|
|
|
+ CT : String;
|
|
|
|
|
|
begin
|
|
begin
|
|
if R.ContentSent then exit;
|
|
if R.ContentSent then exit;
|
|
@@ -294,8 +309,14 @@ begin
|
|
end;
|
|
end;
|
|
If (not R.HeadersSent) then
|
|
If (not R.HeadersSent) then
|
|
begin
|
|
begin
|
|
- R.Code:=500;
|
|
|
|
- R.CodeText:='Application error '+E.ClassName;
|
|
|
|
|
|
+ R.Code:=GetStatusCode;
|
|
|
|
+ if (E is EHTTP) Then
|
|
|
|
+ CT:=EHTTP(E).StatusText
|
|
|
|
+ else
|
|
|
|
+ CT:='';
|
|
|
|
+ if (CT='') then
|
|
|
|
+ CT:='Application error '+E.ClassName;;
|
|
|
|
+ R.CodeText:=CT;
|
|
R.ContentType:='text/html';
|
|
R.ContentType:='text/html';
|
|
end;
|
|
end;
|
|
If (R.ContentType='text/html') then
|
|
If (R.ContentType='text/html') then
|
|
@@ -311,27 +332,27 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWebHandler.InitRequest(ARequest: TRequest);
|
|
|
|
|
|
+Procedure TWebHandler.InitRequest(ARequest: TRequest);
|
|
begin
|
|
begin
|
|
ARequest.OnUnknownEncoding:=Self.OnUnknownRequestEncoding;
|
|
ARequest.OnUnknownEncoding:=Self.OnUnknownRequestEncoding;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWebHandler.InitResponse(AResponse: TResponse);
|
|
|
|
|
|
+Procedure TWebHandler.InitResponse(AResponse: TResponse);
|
|
begin
|
|
begin
|
|
// Do nothing
|
|
// Do nothing
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TWebHandler.GetEmail: String;
|
|
|
|
|
|
+Function TWebHandler.GetEmail: String;
|
|
begin
|
|
begin
|
|
Result := FEmail;
|
|
Result := FEmail;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TWebHandler.GetAdministrator: String;
|
|
|
|
|
|
+Function TWebHandler.GetAdministrator: String;
|
|
begin
|
|
begin
|
|
Result := FAdministrator;
|
|
Result := FAdministrator;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWebHandler.HandleRequest(ARequest: TRequest; AResponse: TResponse);
|
|
|
|
|
|
+Procedure TWebHandler.HandleRequest(ARequest: TRequest; AResponse: TResponse);
|
|
Var
|
|
Var
|
|
MC : TCustomHTTPModuleClass;
|
|
MC : TCustomHTTPModuleClass;
|
|
M : TCustomHTTPModule;
|
|
M : TCustomHTTPModule;
|
|
@@ -350,7 +371,7 @@ begin
|
|
MN:=GetModuleName(ARequest);
|
|
MN:=GetModuleName(ARequest);
|
|
MI:=ModuleFactory.FindModule(MN);
|
|
MI:=ModuleFactory.FindModule(MN);
|
|
if (MI=Nil) then
|
|
if (MI=Nil) then
|
|
- Raise EFPWebError.CreateFmt(SErrNoModuleForRequest,[MN]);
|
|
|
|
|
|
+ DoError(SErrNoModuleForRequest,[MN],400,'Not found');
|
|
MC:=MI.ModuleClass;
|
|
MC:=MI.ModuleClass;
|
|
end;
|
|
end;
|
|
M:=FindModule(MC); // Check if a module exists already
|
|
M:=FindModule(MC); // Check if a module exists already
|
|
@@ -386,6 +407,24 @@ begin
|
|
Result:=ARequest.ScriptName;
|
|
Result:=ARequest.ScriptName;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+Class Procedure TWebHandler.DoError(Msg : String;AStatusCode : Integer = 0; AStatusText : String = '');
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ E : EFPWebError;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ E:=EFPWebError.Create(Msg);
|
|
|
|
+ E.StatusCode:=AStatusCode;
|
|
|
|
+ E.StatusText:=AStatusText;
|
|
|
|
+ Raise E;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+Class Procedure TWebHandler.DoError(Fmt: String; Const Args: Array of const;
|
|
|
|
+ AStatusCode: Integer = 0; AStatusText: String = '');
|
|
|
|
+begin
|
|
|
|
+ DoError(Format(Fmt,Args),AStatusCode,AStatusText);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TWebHandler.Terminate;
|
|
procedure TWebHandler.Terminate;
|
|
begin
|
|
begin
|
|
FTerminated := true;
|
|
FTerminated := true;
|
|
@@ -393,7 +432,7 @@ begin
|
|
FOnTerminate(Self);
|
|
FOnTerminate(Self);
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TWebHandler.GetModuleName(Arequest: TRequest): string;
|
|
|
|
|
|
+Function TWebHandler.GetModuleName(Arequest: TRequest): string;
|
|
|
|
|
|
Function GetDefaultModuleName : String;
|
|
Function GetDefaultModuleName : String;
|
|
|
|
|
|
@@ -426,7 +465,7 @@ begin
|
|
If (Result='') then
|
|
If (Result='') then
|
|
begin
|
|
begin
|
|
if Not AllowDefaultModule then
|
|
if Not AllowDefaultModule then
|
|
- Raise EFPWebError.Create(SErrNoModuleNameForRequest);
|
|
|
|
|
|
+ DoError(SErrNoModuleNameForRequest,400,'Not found');
|
|
Result:=GetDefaultModuleName
|
|
Result:=GetDefaultModuleName
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -450,8 +489,8 @@ begin
|
|
Result:=Nil;
|
|
Result:=Nil;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWebHandler.SetBaseURL(AModule: TCustomHTTPModule;
|
|
|
|
- Const AModuleName : String; ARequest: TRequest);
|
|
|
|
|
|
+Procedure TWebHandler.SetBaseURL(AModule: TCustomHTTPModule;
|
|
|
|
+ Const AModuleName: String; ARequest: TRequest);
|
|
|
|
|
|
Var
|
|
Var
|
|
S,P : String;
|
|
S,P : String;
|
|
@@ -469,7 +508,7 @@ begin
|
|
AModule.BaseURL:=S+P;
|
|
AModule.BaseURL:=S+P;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWebHandler.DoHandleRequest(ARequest: TRequest; AResponse: TResponse);
|
|
|
|
|
|
+Procedure TWebHandler.DoHandleRequest(ARequest: TRequest; AResponse: TResponse);
|
|
begin
|
|
begin
|
|
Try
|
|
Try
|
|
HandleRequest(ARequest,AResponse);
|
|
HandleRequest(ARequest,AResponse);
|