|
@@ -74,13 +74,15 @@ type
|
|
function GetOnRequest : TRequestEvent;
|
|
function GetOnRequest : TRequestEvent;
|
|
function GetCustomErrorPages: TCustomErrorPages;
|
|
function GetCustomErrorPages: TCustomErrorPages;
|
|
procedure SetCustomErrorPages(const Value: TCustomErrorPages);
|
|
procedure SetCustomErrorPages(const Value: TCustomErrorPages);
|
|
|
|
+ function GetLogger : ILogger;
|
|
|
|
+ procedure SetLogger(const aLogger : ILogger);
|
|
function GetHost: string;
|
|
function GetHost: string;
|
|
function GetPort: Integer;
|
|
function GetPort: Integer;
|
|
property OnNewRequest : TRequestEvent read GetOnRequest write SetOnRequest;
|
|
property OnNewRequest : TRequestEvent read GetOnRequest write SetOnRequest;
|
|
property CustomErrorPages : TCustomErrorPages read GetCustomErrorPages write SetCustomErrorPages;
|
|
property CustomErrorPages : TCustomErrorPages read GetCustomErrorPages write SetCustomErrorPages;
|
|
property Host : string read GetHost;
|
|
property Host : string read GetHost;
|
|
property Port : Integer read GetPort;
|
|
property Port : Integer read GetPort;
|
|
- function Logger : ILogger;
|
|
|
|
|
|
+ property Logger : ILogger read GetLogger write SetLogger;
|
|
procedure Start;
|
|
procedure Start;
|
|
procedure Stop;
|
|
procedure Stop;
|
|
end;
|
|
end;
|
|
@@ -95,6 +97,8 @@ type
|
|
function GetOnRequest : TRequestEvent;
|
|
function GetOnRequest : TRequestEvent;
|
|
function GetCustomErrorPages: TCustomErrorPages;
|
|
function GetCustomErrorPages: TCustomErrorPages;
|
|
procedure SetCustomErrorPages(const Value: TCustomErrorPages);
|
|
procedure SetCustomErrorPages(const Value: TCustomErrorPages);
|
|
|
|
+ function GetLogger : ILogger;
|
|
|
|
+ procedure SetLogger(const aLogger : ILogger);
|
|
function GetHost: string;
|
|
function GetHost: string;
|
|
function GetPort: Integer;
|
|
function GetPort: Integer;
|
|
protected
|
|
protected
|
|
@@ -112,7 +116,7 @@ type
|
|
property OnNewRequest : TRequestEvent read GetOnRequest write SetOnRequest;
|
|
property OnNewRequest : TRequestEvent read GetOnRequest write SetOnRequest;
|
|
property OnConnect : TOnConnectEvent read fOnConnect write fOnConnect;
|
|
property OnConnect : TOnConnectEvent read fOnConnect write fOnConnect;
|
|
property OnDisconnect : TOnDisconnectEvent read fOnDisconnect write fOnDisconnect;
|
|
property OnDisconnect : TOnDisconnectEvent read fOnDisconnect write fOnDisconnect;
|
|
- function Logger : ILogger;
|
|
|
|
|
|
+ property Logger : ILogger read GetLogger write SetLogger;
|
|
procedure Start; virtual; abstract;
|
|
procedure Start; virtual; abstract;
|
|
procedure Stop; virtual; abstract;
|
|
procedure Stop; virtual; abstract;
|
|
end;
|
|
end;
|
|
@@ -237,6 +241,11 @@ begin
|
|
Result := fHost;
|
|
Result := fHost;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TCustomHttpServer.GetLogger: ILogger;
|
|
|
|
+begin
|
|
|
|
+ Result := fLogger;
|
|
|
|
+end;
|
|
|
|
+
|
|
function TCustomHttpServer.GetOnRequest: TRequestEvent;
|
|
function TCustomHttpServer.GetOnRequest: TRequestEvent;
|
|
begin
|
|
begin
|
|
Result := fOnRequest;
|
|
Result := fOnRequest;
|
|
@@ -252,14 +261,14 @@ begin
|
|
fCustomErrorPages := Value;
|
|
fCustomErrorPages := Value;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TCustomHttpServer.SetOnRequest(aRequestEvent: TRequestEvent);
|
|
|
|
|
|
+procedure TCustomHttpServer.SetLogger(const aLogger: ILogger);
|
|
begin
|
|
begin
|
|
- fOnRequest := aRequestEvent;
|
|
|
|
|
|
+ fLogger := aLogger;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TCustomHttpServer.Logger: ILogger;
|
|
|
|
|
|
+procedure TCustomHttpServer.SetOnRequest(aRequestEvent: TRequestEvent);
|
|
begin
|
|
begin
|
|
- Result := fLogger;
|
|
|
|
|
|
+ fOnRequest := aRequestEvent;
|
|
end;
|
|
end;
|
|
|
|
|
|
{ THTTPServer }
|
|
{ THTTPServer }
|
|
@@ -335,6 +344,9 @@ begin
|
|
Result.ContentType := aRequestInfo.ContentType;
|
|
Result.ContentType := aRequestInfo.ContentType;
|
|
Result.ContentEncoding := aRequestInfo.ContentEncoding;
|
|
Result.ContentEncoding := aRequestInfo.ContentEncoding;
|
|
Result.ContentLength := aRequestInfo.ContentLength;
|
|
Result.ContentLength := aRequestInfo.ContentLength;
|
|
|
|
+ {$IFDEF DEBUG_HTTPSERVER}
|
|
|
|
+ TDebugger.Trace(Self,'Request: Headers (%s)',[aRequestInfo.RawHeaders.Text]);
|
|
|
|
+ {$ENDIF}
|
|
for i := 0 to aRequestInfo.RawHeaders.Count -1 do
|
|
for i := 0 to aRequestInfo.RawHeaders.Count -1 do
|
|
begin
|
|
begin
|
|
if not StrInArray(aRequestInfo.RawHeaders.Names[i],['Host','Accept-Encoding','Accept','User-Agent','Connection','Cache-Control']) then
|
|
if not StrInArray(aRequestInfo.RawHeaders.Names[i],['Host','Accept-Encoding','Accept','User-Agent','Connection','Cache-Control']) then
|
|
@@ -407,7 +419,11 @@ begin
|
|
on E : Exception do
|
|
on E : Exception do
|
|
begin
|
|
begin
|
|
//get unexpected exception
|
|
//get unexpected exception
|
|
- if E.InheritsFrom(EControlledException) then response.ContentText := response.ContentText + '<BR>' + e.Message
|
|
|
|
|
|
+ if E.InheritsFrom(EControlledException) then
|
|
|
|
+ begin
|
|
|
|
+ Logger.Error('Request: %s %s [%d %s] %s',[request.GetMethodAsString,request.URL, response.StatusCode, response.StatusText,e.Message]);
|
|
|
|
+ response.ContentText := response.ContentText + '<BR>' + e.Message;
|
|
|
|
+ end
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
if response.StatusCode = 200 then
|
|
if response.StatusCode = 200 then
|
|
@@ -416,6 +432,9 @@ begin
|
|
response.StatusText := 'Internal server error';
|
|
response.StatusText := 'Internal server error';
|
|
end;
|
|
end;
|
|
response.ContentText := e.Message;
|
|
response.ContentText := e.Message;
|
|
|
|
+ //log error
|
|
|
|
+ if response.StatusCode = 404 then Logger.Warn('Request: %s %s [%d %s] %s',[request.GetMethodAsString,request.URL, response.StatusCode, response.StatusText,e.Message])
|
|
|
|
+ else Logger.Error('Request: %s %s [%d %s] %s',[request.GetMethodAsString,request.URL, response.StatusCode, response.StatusText,e.Message]);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|