# HG changeset patch # User Sebastien Jodogne # Date 1561061580 -7200 # Node ID d97ef941d52189916ea55c2216422f7ded93e4c5 # Parent dbaf439c8888619e587626ce00887c7c33a41baa compatibility mode for OrthancPlugins::HttpClient::IAnswer diff -r dbaf439c8888 -r d97ef941d521 Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Thu Jun 20 18:36:48 2019 +0200 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Thu Jun 20 22:13:00 2019 +0200 @@ -2668,9 +2668,9 @@ } -#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 void HttpClient::Execute(IAnswer& answer) { +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 if (chunkedBody_ != NULL) { ExecuteWithStream(httpStatus_, answer, *chunkedBody_); @@ -2680,8 +2680,27 @@ MemoryRequestBody wrapper(fullBody_); ExecuteWithStream(httpStatus_, answer, wrapper); } +#else + // Compatibility mode for Orthanc SDK <= 1.5.6. This results in + // higher memory usage (all chunks from the answer body are sent + // at once) + + HttpHeaders answerHeaders; + std::string answerBody; + Execute(answerHeaders, answerBody); + + for (HttpHeaders::const_iterator it = answerHeaders.begin(); + it != answerHeaders.end(); ++it) + { + answer.AddHeader(it->first, it->second); + } + + if (!answerBody.empty()) + { + answer.AddChunk(answerBody.c_str(), answerBody.size()); + } +#endif } -#endif void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, @@ -2695,7 +2714,7 @@ #else // Compatibility mode for Orthanc SDK <= 1.5.6. This results in - // higher memory usage (all chunks from the body request are sent + // higher memory usage (all chunks from the request body are sent // at once) if (chunkedBody_ != NULL) diff -r dbaf439c8888 -r d97ef941d521 Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Thu Jun 20 18:36:48 2019 +0200 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Thu Jun 20 22:13:00 2019 +0200 @@ -814,7 +814,7 @@ virtual bool ReadNextChunk(std::string& chunk) = 0; }; -#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 + class IAnswer : public boost::noncopyable { public: @@ -828,7 +828,6 @@ virtual void AddChunk(const void* data, size_t size) = 0; }; -#endif private: @@ -924,9 +923,7 @@ void SetBody(IRequestBody& body); -#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 void Execute(IAnswer& answer); -#endif void Execute(HttpHeaders& answerHeaders /* out */, std::string& answerBody /* out */); @@ -1071,9 +1068,6 @@ Internals::ChunkedRequestReaderExecute, Internals::ChunkedRequestReaderFinalize); #else - LogWarning("Performance warning: The plugin was compiled against a pre-1.5.7 version " - "of the Orthanc SDK. Multipart transfers will be entirely stored in RAM."); - OrthancPluginRegisterRestCallbackNoLock( GetGlobalContext(), uri.c_str(), Internals::ChunkedRestCompatibility);