# HG changeset patch # User Sebastien Jodogne # Date 1532600718 -7200 # Node ID 959bd8857eb5a98a0976f95fdee1d7712f7aa694 # Parent ad2c32082653029c7477cacb84db3ba9e2706f5d New configuration option: "HttpVerbose" to debug outgoing HTTP connections diff -r ad2c32082653 -r 959bd8857eb5 Core/HttpClient.cpp --- 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); diff -r ad2c32082653 -r 959bd8857eb5 Core/HttpClient.h --- 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); diff -r ad2c32082653 -r 959bd8857eb5 NEWS --- 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 diff -r ad2c32082653 -r 959bd8857eb5 OrthancServer/main.cpp --- 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", "")); diff -r ad2c32082653 -r 959bd8857eb5 Resources/Configuration.json --- 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,