Mercurial > hg > orthanc
changeset 3443:0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 24 Jun 2019 16:55:28 +0200 |
parents | dd1e68f2d0c0 |
children | 6fe42a335a80 |
files | Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h |
diffstat | 2 files changed, 46 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Mon Jun 24 16:06:47 2019 +0200 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Mon Jun 24 16:55:28 2019 +0200 @@ -2285,7 +2285,8 @@ method_(OrthancPluginHttpMethod_Get), timeout_(0), pkcs11_(false), - chunkedBody_(NULL) + chunkedBody_(NULL), + allowChunkedTransfers_(true) { } @@ -2668,19 +2669,25 @@ void HttpClient::Execute(IAnswer& answer) { #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 - if (chunkedBody_ != NULL) - { - ExecuteWithStream(httpStatus_, answer, *chunkedBody_); - } - else + if (allowChunkedTransfers_) { - MemoryRequestBody wrapper(fullBody_); - ExecuteWithStream(httpStatus_, answer, wrapper); + if (chunkedBody_ != NULL) + { + ExecuteWithStream(httpStatus_, answer, *chunkedBody_); + } + else + { + MemoryRequestBody wrapper(fullBody_); + ExecuteWithStream(httpStatus_, answer, wrapper); + } + + return; } -#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) +#endif + + // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked + // transfers are disabled. This results in higher memory usage + // (all chunks from the answer body are sent at once) HttpHeaders answerHeaders; std::string answerBody; @@ -2696,7 +2703,6 @@ { answer.AddChunk(answerBody.c_str(), answerBody.size()); } -#endif } @@ -2704,15 +2710,19 @@ std::string& answerBody /* out */) { #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 - MemoryAnswer answer; - Execute(answer); - answerHeaders = answer.GetHeaders(); - answer.GetBody().Flatten(answerBody); - -#else - // Compatibility mode for Orthanc SDK <= 1.5.6. This results in - // higher memory usage (all chunks from the request body are sent - // at once) + if (allowChunkedTransfers_) + { + MemoryAnswer answer; + Execute(answer); + answerHeaders = answer.GetHeaders(); + answer.GetBody().Flatten(answerBody); + return; + } +#endif + + // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked + // transfers are disabled. This results in higher memory usage + // (all chunks from the request body are sent at once) if (chunkedBody_ != NULL) { @@ -2733,7 +2743,6 @@ { ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_); } -#endif }
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Mon Jun 24 16:06:47 2019 +0200 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Mon Jun 24 16:55:28 2019 +0200 @@ -845,7 +845,8 @@ std::string certificateKeyPassword_; bool pkcs11_; std::string fullBody_; - IRequestBody* chunkedBody_; + IRequestBody* chunkedBody_; + bool allowChunkedTransfers_; #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 void ExecuteWithStream(uint16_t& httpStatus, // out @@ -923,6 +924,18 @@ void SetBody(IRequestBody& body); + // This function can be used to disable chunked transfers if the + // remote server is Orthanc with a version <= 1.5.6. + void SetChunkedTransfersAllowed(bool allow) + { + allowChunkedTransfers_ = allow; + } + + bool IsChunkedTransfersAllowed() const + { + return allowChunkedTransfers_; + } + void Execute(IAnswer& answer); void Execute(HttpHeaders& answerHeaders /* out */,