diff OrthancServer/OrthancRestApi/OrthancRestApi.cpp @ 3689:e85bfba2d307

"/instances": Support "Content-Encoding: gzip" to upload gzip-compressed DICOM files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Feb 2020 11:07:56 +0100
parents 94f4a18a79cc
children 2a170a8f1faf
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Tue Feb 25 10:51:26 2020 +0100
+++ b/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Tue Feb 25 11:07:56 2020 +0100
@@ -34,11 +34,14 @@
 #include "../PrecompiledHeadersServer.h"
 #include "OrthancRestApi.h"
 
+#include "../../Core/Compression/GzipCompressor.h"
 #include "../../Core/Logging.h"
 #include "../../Core/MetricsRegistry.h"
 #include "../../Core/SerializationToolbox.h"
 #include "../ServerContext.h"
 
+#include <boost/algorithm/string/predicate.hpp>
+
 namespace Orthanc
 {
   static void SetupResourceAnswer(Json::Value& result,
@@ -118,13 +121,22 @@
                              "Received an empty DICOM file");
     }
 
-    // TODO Remove unneccessary memcpy
-    std::string postData;
-    call.BodyToString(postData);
+    std::string dicom;
+
+    if (boost::iequals(call.GetHttpHeader("content-encoding", ""), "gzip"))
+    {
+      GzipCompressor compressor;
+      compressor.Uncompress(dicom, call.GetBodyData(), call.GetBodySize());
+    }
+    else
+    {
+      // TODO Remove unneccessary memcpy
+      call.BodyToString(dicom);
+    }
 
     DicomInstanceToStore toStore;
     toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
-    toStore.SetBuffer(postData);
+    toStore.SetBuffer(dicom);
 
     std::string publicId;
     StoreStatus status = context.Store(publicId, toStore);