# HG changeset patch # User Sebastien Jodogne # Date 1561388128 -7200 # Node ID 0371b65d5f76014d19ad8940de9fe3c0dda23860 # Parent dd1e68f2d0c06cd70e9d64bd878d56de3ea2deb9 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed() diff -r dd1e68f2d0c0 -r 0371b65d5f76 Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- 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 } diff -r dd1e68f2d0c0 -r 0371b65d5f76 Plugins/Samples/Common/OrthancPluginCppWrapper.h --- 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 */,