comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3394:2f82ef41bf5a

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Jun 2019 16:42:41 +0200
parents 2cd0369a156f
children 9019279dbfd7
comparison
equal deleted inserted replaced
3393:2cd0369a156f 3394:2f82ef41bf5a
31 **/ 31 **/
32 32
33 33
34 #include "OrthancPluginCppWrapper.h" 34 #include "OrthancPluginCppWrapper.h"
35 35
36 #include <boost/algorithm/string/predicate.hpp>
36 #include <json/reader.h> 37 #include <json/reader.h>
37 #include <json/writer.h> 38 #include <json/writer.h>
38 39
39 40
40 namespace OrthancPlugins 41 namespace OrthancPlugins
2260 headersKeys_.push_back(it->first.c_str()); 2261 headersKeys_.push_back(it->first.c_str());
2261 headersValues_.push_back(it->second.c_str()); 2262 headersValues_.push_back(it->second.c_str());
2262 } 2263 }
2263 } 2264 }
2264 2265
2266 void AddStaticString(const char* key,
2267 const char* value)
2268 {
2269 headersKeys_.push_back(key);
2270 headersValues_.push_back(value);
2271 }
2272
2265 uint32_t GetCount() const 2273 uint32_t GetCount() const
2266 { 2274 {
2267 return headersKeys_.size(); 2275 return headersKeys_.size();
2268 } 2276 }
2269 2277
2403 #if HAS_ORTHANC_PLUGIN_STREAMING_HTTP_CLIENT == 1 2411 #if HAS_ORTHANC_PLUGIN_STREAMING_HTTP_CLIENT == 1
2404 void HttpClient::ExecuteWithStream(uint16_t& httpStatus, 2412 void HttpClient::ExecuteWithStream(uint16_t& httpStatus,
2405 IAnswer& answer, 2413 IAnswer& answer,
2406 IRequestBody& body) const 2414 IRequestBody& body) const
2407 { 2415 {
2408 std::auto_ptr<HeadersWrapper> h; 2416 HeadersWrapper h(headers_);
2409 2417
2410 // Automatically set the "Transfer-Encoding" header if absent 2418 // Automatically set the "Transfer-Encoding" header if absent
2411 if (headers_.find("Transfer-Encoding") == headers_.end()) 2419 bool found = false;
2412 { 2420
2413 HttpHeaders tmp = headers_; 2421 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
2414 tmp["Transfer-Encoding"] = "chunked"; 2422 {
2415 h.reset(new HeadersWrapper(tmp)); 2423 if (boost::iequals(it->first, "Transfer-Encoding"))
2416 } 2424 {
2417 else 2425 found = true;
2418 { 2426 break;
2419 h.reset(new HeadersWrapper(headers_)); 2427 }
2428 }
2429
2430 if (!found)
2431 {
2432 h.AddStaticString("Transfer-Encoding", "chunked");
2420 } 2433 }
2421 2434
2422 RequestBodyWrapper request(body); 2435 RequestBodyWrapper request(body);
2423 2436
2424 OrthancPluginErrorCode error = OrthancPluginStreamingHttpClient( 2437 OrthancPluginErrorCode error = OrthancPluginStreamingHttpClient(
2427 AnswerAddChunkCallback, 2440 AnswerAddChunkCallback,
2428 AnswerAddHeaderCallback, 2441 AnswerAddHeaderCallback,
2429 &httpStatus, 2442 &httpStatus,
2430 method_, 2443 method_,
2431 url_.c_str(), 2444 url_.c_str(),
2432 h->GetCount(), 2445 h.GetCount(),
2433 h->GetKeys(), 2446 h.GetKeys(),
2434 h->GetValues(), 2447 h.GetValues(),
2435 &request, 2448 &request,
2436 RequestBodyWrapper::IsDone, 2449 RequestBodyWrapper::IsDone,
2437 RequestBodyWrapper::GetChunkData, 2450 RequestBodyWrapper::GetChunkData,
2438 RequestBodyWrapper::GetChunkSize, 2451 RequestBodyWrapper::GetChunkSize,
2439 RequestBodyWrapper::Next, 2452 RequestBodyWrapper::Next,