comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3434:6503ab9489ba

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Jun 2019 11:37:18 +0200
parents caa526bb65cc
children dbaf439c8888
comparison
equal deleted inserted replaced
3433:caa526bb65cc 3434:6503ab9489ba
2348 public: 2348 public:
2349 MemoryRequestBody(const std::string& body) : 2349 MemoryRequestBody(const std::string& body) :
2350 body_(body), 2350 body_(body),
2351 done_(false) 2351 done_(false)
2352 { 2352 {
2353 if (body_.empty())
2354 {
2355 done_ = true;
2356 }
2353 } 2357 }
2354 2358
2355 virtual bool ReadNextChunk(std::string& chunk) 2359 virtual bool ReadNextChunk(std::string& chunk)
2356 { 2360 {
2357 if (done_) 2361 if (done_)
2475 IAnswer& answer, 2479 IAnswer& answer,
2476 IRequestBody& body) const 2480 IRequestBody& body) const
2477 { 2481 {
2478 HeadersWrapper h(headers_); 2482 HeadersWrapper h(headers_);
2479 2483
2480 // Automatically set the "Transfer-Encoding" header if absent 2484 if (method_ == OrthancPluginHttpMethod_Post ||
2481 bool found = false; 2485 method_ == OrthancPluginHttpMethod_Put)
2482 2486 {
2483 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it) 2487 // Automatically set the "Transfer-Encoding" header if absent
2484 { 2488 bool found = false;
2485 if (boost::iequals(it->first, "Transfer-Encoding")) 2489
2486 { 2490 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
2487 found = true; 2491 {
2488 break; 2492 if (boost::iequals(it->first, "Transfer-Encoding"))
2489 } 2493 {
2490 } 2494 found = true;
2491 2495 break;
2492 if (!found) 2496 }
2493 { 2497 }
2494 h.AddStaticString("Transfer-Encoding", "chunked"); 2498
2499 if (!found)
2500 {
2501 h.AddStaticString("Transfer-Encoding", "chunked");
2502 }
2495 } 2503 }
2496 2504
2497 RequestBodyWrapper request(body); 2505 RequestBodyWrapper request(body);
2498 2506
2499 OrthancPluginErrorCode error = OrthancPluginChunkedHttpClient( 2507 OrthancPluginErrorCode error = OrthancPluginChunkedHttpClient(
2655 LogError("Cannot convert HTTP answer body to JSON"); 2663 LogError("Cannot convert HTTP answer body to JSON");
2656 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 2664 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2657 } 2665 }
2658 } 2666 }
2659 2667
2668
2669 void HttpClient::Execute()
2670 {
2671 HttpHeaders answerHeaders;
2672 std::string body;
2673 Execute(answerHeaders, body);
2674 }
2675
2660 #endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */ 2676 #endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */
2661 2677
2662 2678
2663 2679
2664 2680