diff Core/HttpServer/MongooseServer.cpp @ 1115:da56a7916e8a

Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Sep 2014 17:30:13 +0200
parents ba5c0908600c
children 1d60316c3618
line wrap: on
line diff
--- a/Core/HttpServer/MongooseServer.cpp	Tue Sep 02 15:56:36 2014 +0200
+++ b/Core/HttpServer/MongooseServer.cpp	Tue Sep 02 17:30:13 2014 +0200
@@ -552,7 +552,7 @@
   {
     MongooseServer* that = reinterpret_cast<MongooseServer*>(request->user_data);
     MongooseOutputStream stream(connection);
-    HttpOutput output(stream);
+    HttpOutput output(stream, that->IsKeepAliveEnabled());
 
     // Check remote calls
     if (!that->IsRemoteAccessAllowed() &&
@@ -786,6 +786,7 @@
     ssl_ = false;
     port_ = 8000;
     filter_ = NULL;
+    keepAlive_ = false;
 
 #if ORTHANC_SSL_ENABLED == 1
     // Check for the Heartbleed exploit
@@ -829,7 +830,7 @@
         
         // Optimization reported by Chris Hafey
         // https://groups.google.com/d/msg/orthanc-users/CKueKX0pJ9E/_UCbl8T-VjIJ
-        // "enable_keep_alive", "yes",
+        "enable_keep_alive", (keepAlive_ ? "yes" : "no"),
 
         // Set the SSL certificate, if any. This must be the last option.
         ssl_ ? "ssl_certificate" : NULL,
@@ -917,6 +918,15 @@
 #endif
   }
 
+
+  void MongooseServer::SetKeepAliveEnabled(bool enabled)
+  {
+    Stop();
+    keepAlive_ = enabled;
+    LOG(WARNING) << "HTTP keep alive is " << (enabled ? "enabled" : "disabled");
+  }
+
+
   void MongooseServer::SetAuthenticationEnabled(bool enabled)
   {
     Stop();