changeset 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 9c091747483a
children a9ce35d67c3c
files NEWS OrthancServer/OrthancRestApi/OrthancRestApi.cpp
diffstat 2 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Feb 25 10:51:26 2020 +0100
+++ b/NEWS	Tue Feb 25 11:07:56 2020 +0100
@@ -12,6 +12,7 @@
 * "/tools/log-level": Possibility to access and change the log level without restarting Orthanc
 * added "/instances/{id}/frames/{frame}/rendered" and "/instances/{id}/rendered" routes
   to render frames, taking windowing and resizing into account
+* "/instances": Support "Content-Encoding: gzip" to upload gzip-compressed DICOM files
 
 Plugins
 -------
--- 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);