changeset 3434:6503ab9489ba

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Jun 2019 11:37:18 +0200
parents caa526bb65cc
children c08bb6ac3b7f
files Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h
diffstat 2 files changed, 30 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Tue Jun 18 09:10:27 2019 +0200
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Tue Jun 18 11:37:18 2019 +0200
@@ -2350,6 +2350,10 @@
         body_(body),
         done_(false)
       {
+        if (body_.empty())
+        {
+          done_ = true;
+        }
       }
 
       virtual bool ReadNextChunk(std::string& chunk)
@@ -2477,21 +2481,25 @@
   {
     HeadersWrapper h(headers_);
 
-    // Automatically set the "Transfer-Encoding" header if absent
-    bool found = false;
-
-    for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
+    if (method_ == OrthancPluginHttpMethod_Post ||
+        method_ == OrthancPluginHttpMethod_Put)
     {
-      if (boost::iequals(it->first, "Transfer-Encoding"))
+      // Automatically set the "Transfer-Encoding" header if absent
+      bool found = false;
+
+      for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
       {
-        found = true;
-        break;
+        if (boost::iequals(it->first, "Transfer-Encoding"))
+        {
+          found = true;
+          break;
+        }
       }
-    }
-
-    if (!found)
-    {
-      h.AddStaticString("Transfer-Encoding", "chunked");
+
+      if (!found)
+      {
+        h.AddStaticString("Transfer-Encoding", "chunked");
+      }
     }
 
     RequestBodyWrapper request(body);
@@ -2657,6 +2665,14 @@
     }
   }
 
+
+  void HttpClient::Execute()
+  {
+    HttpHeaders answerHeaders;
+    std::string body;
+    Execute(answerHeaders, body);
+  }
+
 #endif  /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */
 
 
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Tue Jun 18 09:10:27 2019 +0200
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Tue Jun 18 11:37:18 2019 +0200
@@ -929,6 +929,8 @@
 
     void Execute(HttpHeaders& answerHeaders /* out */,
                  Json::Value& answerBody /* out */);
+
+    void Execute();
   };
 #endif