diff 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
line wrap: on
line diff
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Thu Jun 06 16:12:55 2019 +0200
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Thu Jun 06 16:42:41 2019 +0200
@@ -33,6 +33,7 @@
 
 #include "OrthancPluginCppWrapper.h"
 
+#include <boost/algorithm/string/predicate.hpp>
 #include <json/reader.h>
 #include <json/writer.h>
 
@@ -2262,6 +2263,13 @@
         }
       }
 
+      void AddStaticString(const char* key,
+                           const char* value)
+      {
+        headersKeys_.push_back(key);
+        headersValues_.push_back(value);
+      }
+
       uint32_t GetCount() const
       {
         return headersKeys_.size();
@@ -2405,18 +2413,23 @@
                                      IAnswer& answer,
                                      IRequestBody& body) const
   {
-    std::auto_ptr<HeadersWrapper> h;
+    HeadersWrapper h(headers_);
 
     // Automatically set the "Transfer-Encoding" header if absent
-    if (headers_.find("Transfer-Encoding") == headers_.end())
+    bool found = false;
+
+    for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
     {
-      HttpHeaders tmp = headers_;
-      tmp["Transfer-Encoding"] = "chunked";
-      h.reset(new HeadersWrapper(tmp));
+      if (boost::iequals(it->first, "Transfer-Encoding"))
+      {
+        found = true;
+        break;
+      }
     }
-    else
+
+    if (!found)
     {
-      h.reset(new HeadersWrapper(headers_));
+      h.AddStaticString("Transfer-Encoding", "chunked");
     }
 
     RequestBodyWrapper request(body);
@@ -2429,9 +2442,9 @@
       &httpStatus,
       method_,
       url_.c_str(),
-      h->GetCount(),
-      h->GetKeys(),
-      h->GetValues(),
+      h.GetCount(),
+      h.GetKeys(),
+      h.GetValues(),
       &request,
       RequestBodyWrapper::IsDone,
       RequestBodyWrapper::GetChunkData,