|
@@ -65,7 +65,7 @@ Type
|
|
|
FSocket: TSocketStream;
|
|
|
FSetupSocket : Boolean;
|
|
|
FBuffer : Ansistring;
|
|
|
- FKeepAliveEnabled : Boolean;
|
|
|
+ FEnableKeepAlive : Boolean;
|
|
|
FKeepAlive : Boolean;
|
|
|
FKeepAliveTimeout : Integer;
|
|
|
procedure InterPretHeader(ARequest: TFPHTTPConnectionRequest; const AHeader: String);
|
|
@@ -85,8 +85,12 @@ Type
|
|
|
Property Server : TFPCustomHTTPServer Read FServer;
|
|
|
Property OnRequestError : TRequestErrorHandler Read FOnError Write FOnError;
|
|
|
Property LookupHostNames : Boolean Read GetLookupHostNames;
|
|
|
- Property KeepAliveEnabled: Boolean read FKeepAliveEnabled write FKeepAliveEnabled;
|
|
|
+
|
|
|
+ // Set to true if you want to support HTTP 1.1 connection: keep-alive - only available for threaded server
|
|
|
+ Property EnableKeepAlive: Boolean read FEnableKeepAlive write FEnableKeepAlive;
|
|
|
+ // time-out for keep-alive: how many ms should the server keep the connection alive after a request has been handled
|
|
|
Property KeepAliveTimeout: Integer read FKeepAliveTimeout write FKeepAliveTimeout;
|
|
|
+ // is the current connection set up for KeepAlive?
|
|
|
Property KeepAlive: Boolean read FKeepAlive;
|
|
|
end;
|
|
|
|
|
@@ -133,8 +137,6 @@ Type
|
|
|
FConnectionThreadList: TThreadList;
|
|
|
FConnectionCount : Integer;
|
|
|
FUseSSL: Boolean;
|
|
|
- FKeepAliveEnabled: Boolean;
|
|
|
- FKeepAliveTimeout: Integer;
|
|
|
procedure DoCreateClientHandler(Sender: TObject; out AHandler: TSocketHandler);
|
|
|
function GetActive: Boolean;
|
|
|
function GetHostName: string;
|
|
@@ -227,11 +229,6 @@ Type
|
|
|
Property OnGetSocketHandler : TGetSocketHandlerEvent Read FOnGetSocketHandler Write FOnGetSocketHandler;
|
|
|
// Called after create socket handler was created, with the created socket handler.
|
|
|
Property AfterSocketHandlerCreate : TSocketHandlerCreatedEvent Read FAfterSocketHandlerCreated Write FAfterSocketHandlerCreated;
|
|
|
-
|
|
|
- // Set to true if you want to support HTTP 1.1 connection: keep-alive - only available for threaded server
|
|
|
- Property KeepAliveEnabled: Boolean read FKeepAliveEnabled write FKeepAliveEnabled;
|
|
|
- // time-out for keep-alive: how many ms should the server keep the connection alive after a request has been handled
|
|
|
- Property KeepAliveTimeout: Integer read FKeepAliveTimeout write FKeepAliveTimeout;
|
|
|
end;
|
|
|
|
|
|
TFPHttpServer = Class(TFPCustomHttpServer)
|
|
@@ -583,7 +580,7 @@ begin
|
|
|
If Req.ContentLength>0 then
|
|
|
ReadRequestContent(Req);
|
|
|
Req.InitRequestVars;
|
|
|
- if KeepAliveEnabled then
|
|
|
+ if EnableKeepAlive then
|
|
|
begin
|
|
|
// Read out keep-alive
|
|
|
FKeepAlive:=Req.HttpVersion='1.1'; // keep-alive is default on HTTP 1.1
|
|
@@ -642,12 +639,12 @@ begin
|
|
|
try
|
|
|
try
|
|
|
repeat
|
|
|
- if Connection.KeepAliveEnabled and Connection.KeepAlive
|
|
|
+ if Connection.EnableKeepAlive and Connection.KeepAlive
|
|
|
and not Connection.Socket.CanRead(Connection.KeepAliveTimeout) then
|
|
|
break;
|
|
|
|
|
|
FConnection.HandleRequest;
|
|
|
- until not (FConnection.KeepAliveEnabled and FConnection.KeepAlive and (FConnection.Socket.LastError=0));
|
|
|
+ until not (FConnection.EnableKeepAlive and FConnection.KeepAlive and (FConnection.Socket.LastError=0));
|
|
|
finally
|
|
|
FreeAndNil(FConnection);
|
|
|
if Assigned(FThreadList) then
|
|
@@ -830,11 +827,7 @@ begin
|
|
|
Con.FServer:=Self;
|
|
|
Con.OnRequestError:=@HandleRequestError;
|
|
|
if Threaded then
|
|
|
- begin
|
|
|
- Con.KeepAliveEnabled:=KeepAliveEnabled;
|
|
|
- Con.KeepAliveTimeout:=KeepAliveTimeout;
|
|
|
- CreateConnectionThread(Con);
|
|
|
- end
|
|
|
+ CreateConnectionThread(Con)
|
|
|
else
|
|
|
begin
|
|
|
Con.HandleRequest;
|