changeset 2788:959bd8857eb5

New configuration option: "HttpVerbose" to debug outgoing HTTP connections
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 26 Jul 2018 12:25:18 +0200
parents ad2c32082653
children 2a4ac74da1ed
files Core/HttpClient.cpp Core/HttpClient.h NEWS OrthancServer/main.cpp Resources/Configuration.json
diffstat 5 files changed, 68 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpClient.cpp	Thu Jul 26 10:33:36 2018 +0200
+++ b/Core/HttpClient.cpp	Thu Jul 26 12:25:18 2018 +0200
@@ -95,10 +95,12 @@
     std::string     httpsCACertificates_;
     std::string     proxy_;
     long            timeout_;
+    bool            verbose_;
 
     GlobalParameters() : 
       httpsVerifyPeers_(true),
-      timeout_(0)
+      timeout_(0),
+      verbose_(false)
     {
     }
 
@@ -173,6 +175,16 @@
       Pkcs11::Initialize(module, pin, verbose);
     }
 #endif
+
+    bool IsDefaultVerbose() const
+    {
+      return verbose_;
+    }
+
+    void SetDefaultVerbose(bool verbose) 
+    {
+      verbose_ = verbose;
+    }
   };
 
 
@@ -240,6 +252,36 @@
   }
 
 
+  /*static int CurlDebugCallback(CURL *handle,
+                               curl_infotype type,
+                               char *data,
+                               size_t size,
+                               void *userptr)
+  {
+    switch (type)
+    {
+      case CURLINFO_TEXT:
+      case CURLINFO_HEADER_IN:
+      case CURLINFO_HEADER_OUT:
+      case CURLINFO_SSL_DATA_IN:
+      case CURLINFO_SSL_DATA_OUT:
+      case CURLINFO_END:
+      case CURLINFO_DATA_IN:
+      case CURLINFO_DATA_OUT:
+      {
+        std::string s(data, size);
+        LOG(INFO) << "libcurl: " << s;
+        break;
+      }
+
+      default:
+        break;
+    }
+
+    return 0;
+    }*/
+
+
   struct CurlHeaderParameters
   {
     bool lowerCase_;
@@ -314,7 +356,7 @@
     url_ = "";
     method_ = HttpMethod_Get;
     lastStatus_ = HttpStatus_200_Ok;
-    SetVerbose(false);
+    SetVerbose(GlobalParameters::GetInstance().IsDefaultVerbose());
     timeout_ = GlobalParameters::GetInstance().GetDefaultTimeout();
     GlobalParameters::GetInstance().GetDefaultProxy(proxy_);
     GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_);    
@@ -376,6 +418,7 @@
     if (isVerbose_)
     {
       CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 1));
+      //CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_DEBUGFUNCTION, &CurlDebugCallback));
     }
     else
     {
@@ -613,6 +656,14 @@
       code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status);
     }
 
+    LOG(INFO) << "HTTP status code " << status << " after "
+              << EnumerationToString(method_) << " request on: " << url_;
+
+    if (isVerbose_)
+    {
+      LOG(INFO) << "cURL status code: " << code;
+    }
+
     CheckCode(code);
 
     if (status == 0)
@@ -711,6 +762,12 @@
   }
   
 
+  void HttpClient::SetDefaultVerbose(bool verbose)
+  {
+    GlobalParameters::GetInstance().SetDefaultVerbose(verbose);
+  }
+
+
   void HttpClient::SetDefaultProxy(const std::string& proxy)
   {
     GlobalParameters::GetInstance().SetDefaultProxy(proxy);
--- a/Core/HttpClient.h	Thu Jul 26 10:33:36 2018 +0200
+++ b/Core/HttpClient.h	Thu Jul 26 12:25:18 2018 +0200
@@ -275,6 +275,8 @@
     static void ConfigureSsl(bool httpsVerifyPeers,
                              const std::string& httpsCACertificates);
 
+    static void SetDefaultVerbose(bool verbose);
+
     static void SetDefaultProxy(const std::string& proxy);
 
     static void SetDefaultTimeout(long timeout);
--- a/NEWS	Thu Jul 26 10:33:36 2018 +0200
+++ b/NEWS	Thu Jul 26 12:25:18 2018 +0200
@@ -1,6 +1,7 @@
 Pending changes in the mainline
 ===============================
 
+* New configuration option: "HttpVerbose" to debug outgoing HTTP connections
 * Fix incoming DICOM C-Store filtering for JPEG-LS transfer syntaxes
 * Fix OrthancPluginHttpClient() to return the HTTP status on errors
 
--- a/OrthancServer/main.cpp	Thu Jul 26 10:33:36 2018 +0200
+++ b/OrthancServer/main.cpp	Thu Jul 26 12:25:18 2018 +0200
@@ -967,6 +967,7 @@
   HttpClient::ConfigureSsl(Configuration::GetGlobalBoolParameter("HttpsVerifyPeers", true),
                            Configuration::InterpretStringParameterAsPath
                            (Configuration::GetGlobalStringParameter("HttpsCACertificates", "")));
+  HttpClient::SetDefaultVerbose(Configuration::GetGlobalBoolParameter("HttpVerbose", false));
   HttpClient::SetDefaultTimeout(Configuration::GetGlobalUnsignedIntegerParameter("HttpTimeout", 0));
   HttpClient::SetDefaultProxy(Configuration::GetGlobalStringParameter("HttpProxy", ""));
 
--- a/Resources/Configuration.json	Thu Jul 26 10:33:36 2018 +0200
+++ b/Resources/Configuration.json	Thu Jul 26 12:25:18 2018 +0200
@@ -231,6 +231,11 @@
   //   "HttpProxy" : "proxyUser:proxyPassword@192.168.0.1:3128"
   "HttpProxy" : "",
 
+  // If set to "true", debug messages from libcurl will be issued
+  // whenever Orthanc makes an outgoing HTTP request. This is notably
+  // useful to debug HTTPS-related problems.
+  "HttpVerbose" : false,
+
   // Set the timeout for HTTP requests issued by Orthanc (in seconds).
   "HttpTimeout" : 10,