changeset 3380:0528a6c36f3d

HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 May 2019 12:06:26 +0200
parents 974e12006b7d
children a6c590cb8181
files Core/HttpServer/HttpOutput.cpp NEWS
diffstat 2 files changed, 43 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp	Fri May 17 08:42:24 2019 +0200
+++ b/Core/HttpServer/HttpOutput.cpp	Thu May 23 12:06:26 2019 +0200
@@ -34,11 +34,12 @@
 #include "../PrecompiledHeaders.h"
 #include "HttpOutput.h"
 
+#include "../ChunkedBuffer.h"
+#include "../Compression/GzipCompressor.h"
+#include "../Compression/ZlibCompressor.h"
 #include "../Logging.h"
 #include "../OrthancException.h"
 #include "../Toolbox.h"
-#include "../Compression/GzipCompressor.h"
-#include "../Compression/ZlibCompressor.h"
 
 #include <iostream>
 #include <vector>
@@ -599,6 +600,34 @@
   }
 
 
+  static void AnswerStreamAsBuffer(HttpOutput& output,
+                                   IHttpStreamAnswer& stream)
+  {
+    ChunkedBuffer buffer;
+
+    while (stream.ReadNextChunk())
+    {
+      if (stream.GetChunkSize() > 0)
+      {
+        buffer.AddChunk(stream.GetChunkContent(), stream.GetChunkSize());
+      }
+    }
+
+    std::string s;
+    buffer.Flatten(s);
+
+    output.SetContentType(stream.GetContentType());
+    
+    std::string filename;
+    if (stream.HasContentFilename(filename))
+    {
+      output.SetContentFilename(filename.c_str());
+    }
+
+    output.Answer(s);
+  }
+
+
   void HttpOutput::Answer(IHttpStreamAnswer& stream)
   {
     HttpCompression compression = stream.SetupHttpCompression(isGzipAllowed_, isDeflateAllowed_);
@@ -606,7 +635,18 @@
     switch (compression)
     {
       case HttpCompression_None:
+      {
+        if (isGzipAllowed_ || isDeflateAllowed_)
+        {
+          // New in Orthanc 1.5.7: Compress streams without built-in
+          // compression, if requested by the "Accept-Encoding" HTTP
+          // header
+          AnswerStreamAsBuffer(*this, stream);
+          return;
+        }
+        
         break;
+      }
 
       case HttpCompression_Gzip:
         stateMachine_.AddHeader("Content-Encoding", "gzip");
--- a/NEWS	Fri May 17 08:42:24 2019 +0200
+++ b/NEWS	Thu May 23 12:06:26 2019 +0200
@@ -16,6 +16,7 @@
 * Size of the Orthanc static binaries are reduced by compressing ICU data
 * Anonymization: Preserve hierarchical relationships in (0008,1115) [] (0020,000e)
 * Allow the serialization of signed 16bpp images in PAM format
+* HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
 * Fix issue #136 (C-FIND request fails when found DICOM file does not have certain tags)
 * Fix issue #137 (C-STORE fails for unknown SOP Class although server is configured to accept any)
 * Fix issue #138 (POST to modalities/{name} accepts invalid characters)