Mercurial > hg > orthanc
comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3443:0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 24 Jun 2019 16:55:28 +0200 |
parents | 77702c19a2fa |
children | f93a9c6c00c5 |
comparison
equal
deleted
inserted
replaced
3442:dd1e68f2d0c0 | 3443:0371b65d5f76 |
---|---|
2283 HttpClient::HttpClient() : | 2283 HttpClient::HttpClient() : |
2284 httpStatus_(0), | 2284 httpStatus_(0), |
2285 method_(OrthancPluginHttpMethod_Get), | 2285 method_(OrthancPluginHttpMethod_Get), |
2286 timeout_(0), | 2286 timeout_(0), |
2287 pkcs11_(false), | 2287 pkcs11_(false), |
2288 chunkedBody_(NULL) | 2288 chunkedBody_(NULL), |
2289 allowChunkedTransfers_(true) | |
2289 { | 2290 { |
2290 } | 2291 } |
2291 | 2292 |
2292 | 2293 |
2293 void HttpClient::AddHeaders(const HttpHeaders& headers) | 2294 void HttpClient::AddHeaders(const HttpHeaders& headers) |
2666 | 2667 |
2667 | 2668 |
2668 void HttpClient::Execute(IAnswer& answer) | 2669 void HttpClient::Execute(IAnswer& answer) |
2669 { | 2670 { |
2670 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 | 2671 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
2671 if (chunkedBody_ != NULL) | 2672 if (allowChunkedTransfers_) |
2672 { | 2673 { |
2673 ExecuteWithStream(httpStatus_, answer, *chunkedBody_); | 2674 if (chunkedBody_ != NULL) |
2674 } | 2675 { |
2675 else | 2676 ExecuteWithStream(httpStatus_, answer, *chunkedBody_); |
2676 { | 2677 } |
2677 MemoryRequestBody wrapper(fullBody_); | 2678 else |
2678 ExecuteWithStream(httpStatus_, answer, wrapper); | 2679 { |
2679 } | 2680 MemoryRequestBody wrapper(fullBody_); |
2680 #else | 2681 ExecuteWithStream(httpStatus_, answer, wrapper); |
2681 // Compatibility mode for Orthanc SDK <= 1.5.6. This results in | 2682 } |
2682 // higher memory usage (all chunks from the answer body are sent | 2683 |
2683 // at once) | 2684 return; |
2685 } | |
2686 #endif | |
2687 | |
2688 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked | |
2689 // transfers are disabled. This results in higher memory usage | |
2690 // (all chunks from the answer body are sent at once) | |
2684 | 2691 |
2685 HttpHeaders answerHeaders; | 2692 HttpHeaders answerHeaders; |
2686 std::string answerBody; | 2693 std::string answerBody; |
2687 Execute(answerHeaders, answerBody); | 2694 Execute(answerHeaders, answerBody); |
2688 | 2695 |
2694 | 2701 |
2695 if (!answerBody.empty()) | 2702 if (!answerBody.empty()) |
2696 { | 2703 { |
2697 answer.AddChunk(answerBody.c_str(), answerBody.size()); | 2704 answer.AddChunk(answerBody.c_str(), answerBody.size()); |
2698 } | 2705 } |
2699 #endif | |
2700 } | 2706 } |
2701 | 2707 |
2702 | 2708 |
2703 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, | 2709 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, |
2704 std::string& answerBody /* out */) | 2710 std::string& answerBody /* out */) |
2705 { | 2711 { |
2706 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 | 2712 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
2707 MemoryAnswer answer; | 2713 if (allowChunkedTransfers_) |
2708 Execute(answer); | 2714 { |
2709 answerHeaders = answer.GetHeaders(); | 2715 MemoryAnswer answer; |
2710 answer.GetBody().Flatten(answerBody); | 2716 Execute(answer); |
2711 | 2717 answerHeaders = answer.GetHeaders(); |
2712 #else | 2718 answer.GetBody().Flatten(answerBody); |
2713 // Compatibility mode for Orthanc SDK <= 1.5.6. This results in | 2719 return; |
2714 // higher memory usage (all chunks from the request body are sent | 2720 } |
2715 // at once) | 2721 #endif |
2722 | |
2723 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked | |
2724 // transfers are disabled. This results in higher memory usage | |
2725 // (all chunks from the request body are sent at once) | |
2716 | 2726 |
2717 if (chunkedBody_ != NULL) | 2727 if (chunkedBody_ != NULL) |
2718 { | 2728 { |
2719 ChunkedBuffer buffer; | 2729 ChunkedBuffer buffer; |
2720 | 2730 |
2731 } | 2741 } |
2732 else | 2742 else |
2733 { | 2743 { |
2734 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_); | 2744 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_); |
2735 } | 2745 } |
2736 #endif | |
2737 } | 2746 } |
2738 | 2747 |
2739 | 2748 |
2740 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, | 2749 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, |
2741 Json::Value& answerBody /* out */) | 2750 Json::Value& answerBody /* out */) |