diff Core/HttpServer/HttpOutput.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 1e1390665639
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp	Tue Sep 02 15:56:36 2014 +0200
+++ b/Core/HttpServer/HttpOutput.cpp	Tue Sep 02 17:30:13 2014 +0200
@@ -43,12 +43,14 @@
 
 namespace Orthanc
 {
-  HttpOutput::StateMachine::StateMachine(IHttpOutputStream& stream) : 
+  HttpOutput::StateMachine::StateMachine(IHttpOutputStream& stream,
+                                         bool isKeepAlive) : 
     stream_(stream),
     state_(State_WritingHeader),
     status_(HttpStatus_200_Ok),
     hasContentLength_(false),
-    contentPosition_(0)
+    contentPosition_(0),
+    keepAlive_(isKeepAlive)
   {
   }
 
@@ -160,9 +162,9 @@
         " " + std::string(EnumerationToString(status_)) +
         "\r\n";
 
-      if (status_ != HttpStatus_200_Ok)
+      if (keepAlive_)
       {
-        hasContentLength_ = false;
+        s += "Connection: keep-alive\r\n";
       }
 
       for (std::list<std::string>::const_iterator
@@ -171,6 +173,11 @@
         s += *it;
       }
 
+      if (status_ != HttpStatus_200_Ok)
+      {
+        hasContentLength_ = false;
+      }
+
       uint64_t contentLength = (hasContentLength_ ? contentLength_ : length);
       s += "Content-Length: " + boost::lexical_cast<std::string>(contentLength) + "\r\n\r\n";