Mercurial > hg > orthanc
changeset 3438:d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 Jun 2019 22:13:00 +0200 |
parents | dbaf439c8888 |
children | fbcde0d66ed8 |
files | Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h |
diffstat | 2 files changed, 23 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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<GetHandler, PostHandler, DeleteHandler, PutHandler>);