Browse Source

* Finish merge & rebase

Michaël Van Canneyt 4 years ago
parent
commit
181653162c
1 changed files with 16 additions and 11 deletions
  1. 16 11
      packages/fcl-web/src/base/fphttpserver.pp

+ 16 - 11
packages/fcl-web/src/base/fphttpserver.pp

@@ -67,7 +67,7 @@ Type
     FSocket: TSocketStream;
     FSocket: TSocketStream;
     FSetupSocket : Boolean;
     FSetupSocket : Boolean;
     FBuffer : Ansistring;
     FBuffer : Ansistring;
-    FEnableKeepAlive : Boolean;
+    FKeepAliveEnabled : Boolean;
     FKeepAlive : Boolean;
     FKeepAlive : Boolean;
     FKeepAliveTimeout : Integer;
     FKeepAliveTimeout : Integer;
     procedure InterPretHeader(ARequest: TFPHTTPConnectionRequest; const AHeader: String);
     procedure InterPretHeader(ARequest: TFPHTTPConnectionRequest; const AHeader: String);
@@ -88,8 +88,9 @@ Type
     Property Server : TFPCustomHTTPServer Read FServer;
     Property Server : TFPCustomHTTPServer Read FServer;
     Property OnRequestError : TRequestErrorHandler Read FOnError Write FOnError;
     Property OnRequestError : TRequestErrorHandler Read FOnError Write FOnError;
     Property LookupHostNames : Boolean Read GetLookupHostNames;
     Property LookupHostNames : Boolean Read GetLookupHostNames;
+
     // Set to true if you want to support HTTP 1.1 connection: keep-alive - only available for threaded server
     // 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;
+    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
     // 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;
     Property KeepAliveTimeout: Integer read FKeepAliveTimeout write FKeepAliveTimeout;
     // is the current connection set up for KeepAlive?
     // is the current connection set up for KeepAlive?
@@ -219,7 +220,8 @@ Type
     FAdminName: string;
     FAdminName: string;
     FAfterSocketHandlerCreated: TSocketHandlerCreatedEvent;
     FAfterSocketHandlerCreated: TSocketHandlerCreatedEvent;
     FCertificateData: TCertificateData;
     FCertificateData: TCertificateData;
-    FEnableKeepAlive: Boolean;
+    FKeepAliveEnabled: Boolean;
+    FKeepAliveTimeout: Integer;
     FOnAcceptIdle: TNotifyEvent;
     FOnAcceptIdle: TNotifyEvent;
     FOnAllowConnect: TConnectQuery;
     FOnAllowConnect: TConnectQuery;
     FOnGetSocketHandler: TGetSocketHandlerEvent;
     FOnGetSocketHandler: TGetSocketHandlerEvent;
@@ -306,7 +308,9 @@ Type
     // Port to listen on.
     // Port to listen on.
     Property Port : Word Read FPort Write SetPort Default 80;
     Property Port : Word Read FPort Write SetPort Default 80;
     // Set to true if you want to support HTTP 1.1 connection: keep-alive - only available for threaded server
     // 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;
+    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;
     // Max connections on queue (for Listen call)
     // Max connections on queue (for Listen call)
     Property QueueSize : Word Read FQueueSize Write SetQueueSize Default 5;
     Property QueueSize : Word Read FQueueSize Write SetQueueSize Default 5;
     // Called when deciding whether to accept a connection.
     // Called when deciding whether to accept a connection.
@@ -339,10 +343,6 @@ Type
     Property OnGetSocketHandler : TGetSocketHandlerEvent Read FOnGetSocketHandler Write FOnGetSocketHandler;
     Property OnGetSocketHandler : TGetSocketHandlerEvent Read FOnGetSocketHandler Write FOnGetSocketHandler;
     // Called after create socket handler was created, with the created socket handler.
     // Called after create socket handler was created, with the created socket handler.
     Property AfterSocketHandlerCreate : TSocketHandlerCreatedEvent Read FAfterSocketHandlerCreated Write FAfterSocketHandlerCreated;
     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;
   end;
 
 
   TFPHttpServer = Class(TFPCustomHttpServer)
   TFPHttpServer = Class(TFPCustomHttpServer)
@@ -356,6 +356,8 @@ Type
     Property OnRequestError;
     Property OnRequestError;
     Property OnAcceptIdle;
     Property OnAcceptIdle;
     Property AcceptIdleTimeout;
     Property AcceptIdleTimeout;
+    Property KeepaliveEnabled;
+    Property KeepaliveTimeout;
   end;
   end;
 
 
   EHTTPServer = Class(EHTTP);
   EHTTPServer = Class(EHTTP);
@@ -882,7 +884,7 @@ begin
       If Req.ContentLength>0 then
       If Req.ContentLength>0 then
         ReadRequestContent(Req);
         ReadRequestContent(Req);
       Req.InitRequestVars;
       Req.InitRequestVars;
-      if EnableKeepAlive then
+      if KeepAliveEnabled then
         begin
         begin
         // Read out keep-alive
         // Read out keep-alive
         FKeepAlive:=Req.HttpVersion='1.1'; // keep-alive is default on HTTP 1.1
         FKeepAlive:=Req.HttpVersion='1.1'; // keep-alive is default on HTTP 1.1
@@ -931,7 +933,7 @@ procedure TFPHTTPConnectionThread.Execute;
 
 
   Function AllowReading : Boolean; // inline;
   Function AllowReading : Boolean; // inline;
   begin
   begin
-    Result:=not Terminated and Connection.EnableKeepAlive and Connection.KeepAlive
+    Result:=not Terminated and Connection.KeepAliveEnabled and Connection.KeepAlive
   end;
   end;
 
 
 begin
 begin
@@ -1158,7 +1160,8 @@ begin
   Con:=CreateConnection(Data);
   Con:=CreateConnection(Data);
   Con.FServer:=Self;
   Con.FServer:=Self;
   Con.OnRequestError:=@HandleRequestError;
   Con.OnRequestError:=@HandleRequestError;
-  Con.EnableKeepAlive:=Self.EnableKeepAlive;
+  Con.KeepAliveEnabled:=Self.KeepAliveEnabled;
+  Con.KeepAliveTimeout:=Self.KeepAliveTimeout;
   FConnectionHandler.HandleConnection(Con);
   FConnectionHandler.HandleConnection(Con);
 end;
 end;
 
 
@@ -1224,6 +1227,8 @@ begin
   FQueueSize:=5;
   FQueueSize:=5;
   FServerBanner := 'FreePascal';
   FServerBanner := 'FreePascal';
   FCertificateData:=CreateCertificateData;
   FCertificateData:=CreateCertificateData;
+  FKeepAliveEnabled:=False;
+  FKeepAliveTimeout:=DefaultKeepaliveTimeout;
 end;
 end;