diff OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp @ 4650:9804d6490872

Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 May 2021 10:57:42 +0200
parents d9473bd5ed43
children f0038043fb97 7053502fbf97
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp	Fri Apr 30 10:09:50 2021 +0200
+++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp	Tue May 04 10:57:42 2021 +0200
@@ -63,6 +63,7 @@
     LOG(INFO) << "Sending instance " << instance << " to peer \"" 
               << peer_.GetUrl() << "\"";
 
+    // Lifetime of "body" must exceed the call to "client_->Apply()" because of "SetExternalBody()"
     std::string body;
 
     try
@@ -99,19 +100,24 @@
       return false;
     }
 
+    // Lifetime of "compressedBody" must exceed the call to "client_->Apply()" because of "SetExternalBody()"
+    std::string compressedBody;
+
     if (compress_)
     {
       GzipCompressor compressor;
       compressor.SetCompressionLevel(9);  // Max compression level
-      IBufferCompressor::Compress(client_->GetBody(), compressor, body);
+      IBufferCompressor::Compress(compressedBody, compressor, body);
+
+      client_->SetExternalBody(compressedBody);
+      size_ += compressedBody.size();
     }
     else
     {
-      client_->GetBody().swap(body);
+      client_->SetExternalBody(body);
+      size_ += body.size();
     }
 
-    size_ += client_->GetBody().size();
-
     std::string answer;
     if (client_->Apply(answer))
     {