Mercurial > hg > orthanc
comparison Core/HttpClient.cpp @ 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 | dc7330089736 |
comparison
equal
deleted
inserted
replaced
2787:ad2c32082653 | 2788:959bd8857eb5 |
---|---|
93 boost::mutex mutex_; | 93 boost::mutex mutex_; |
94 bool httpsVerifyPeers_; | 94 bool httpsVerifyPeers_; |
95 std::string httpsCACertificates_; | 95 std::string httpsCACertificates_; |
96 std::string proxy_; | 96 std::string proxy_; |
97 long timeout_; | 97 long timeout_; |
98 bool verbose_; | |
98 | 99 |
99 GlobalParameters() : | 100 GlobalParameters() : |
100 httpsVerifyPeers_(true), | 101 httpsVerifyPeers_(true), |
101 timeout_(0) | 102 timeout_(0), |
103 verbose_(false) | |
102 { | 104 { |
103 } | 105 } |
104 | 106 |
105 public: | 107 public: |
106 // Singleton pattern | 108 // Singleton pattern |
171 { | 173 { |
172 boost::mutex::scoped_lock lock(mutex_); | 174 boost::mutex::scoped_lock lock(mutex_); |
173 Pkcs11::Initialize(module, pin, verbose); | 175 Pkcs11::Initialize(module, pin, verbose); |
174 } | 176 } |
175 #endif | 177 #endif |
178 | |
179 bool IsDefaultVerbose() const | |
180 { | |
181 return verbose_; | |
182 } | |
183 | |
184 void SetDefaultVerbose(bool verbose) | |
185 { | |
186 verbose_ = verbose; | |
187 } | |
176 }; | 188 }; |
177 | 189 |
178 | 190 |
179 struct HttpClient::PImpl | 191 struct HttpClient::PImpl |
180 { | 192 { |
236 { | 248 { |
237 target.AddChunk(buffer, length); | 249 target.AddChunk(buffer, length); |
238 return length; | 250 return length; |
239 } | 251 } |
240 } | 252 } |
253 | |
254 | |
255 /*static int CurlDebugCallback(CURL *handle, | |
256 curl_infotype type, | |
257 char *data, | |
258 size_t size, | |
259 void *userptr) | |
260 { | |
261 switch (type) | |
262 { | |
263 case CURLINFO_TEXT: | |
264 case CURLINFO_HEADER_IN: | |
265 case CURLINFO_HEADER_OUT: | |
266 case CURLINFO_SSL_DATA_IN: | |
267 case CURLINFO_SSL_DATA_OUT: | |
268 case CURLINFO_END: | |
269 case CURLINFO_DATA_IN: | |
270 case CURLINFO_DATA_OUT: | |
271 { | |
272 std::string s(data, size); | |
273 LOG(INFO) << "libcurl: " << s; | |
274 break; | |
275 } | |
276 | |
277 default: | |
278 break; | |
279 } | |
280 | |
281 return 0; | |
282 }*/ | |
241 | 283 |
242 | 284 |
243 struct CurlHeaderParameters | 285 struct CurlHeaderParameters |
244 { | 286 { |
245 bool lowerCase_; | 287 bool lowerCase_; |
312 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); | 354 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); |
313 | 355 |
314 url_ = ""; | 356 url_ = ""; |
315 method_ = HttpMethod_Get; | 357 method_ = HttpMethod_Get; |
316 lastStatus_ = HttpStatus_200_Ok; | 358 lastStatus_ = HttpStatus_200_Ok; |
317 SetVerbose(false); | 359 SetVerbose(GlobalParameters::GetInstance().IsDefaultVerbose()); |
318 timeout_ = GlobalParameters::GetInstance().GetDefaultTimeout(); | 360 timeout_ = GlobalParameters::GetInstance().GetDefaultTimeout(); |
319 GlobalParameters::GetInstance().GetDefaultProxy(proxy_); | 361 GlobalParameters::GetInstance().GetDefaultProxy(proxy_); |
320 GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_); | 362 GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_); |
321 } | 363 } |
322 | 364 |
374 isVerbose_ = isVerbose; | 416 isVerbose_ = isVerbose; |
375 | 417 |
376 if (isVerbose_) | 418 if (isVerbose_) |
377 { | 419 { |
378 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 1)); | 420 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 1)); |
421 //CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_DEBUGFUNCTION, &CurlDebugCallback)); | |
379 } | 422 } |
380 else | 423 else |
381 { | 424 { |
382 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 0)); | 425 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 0)); |
383 } | 426 } |
611 else | 654 else |
612 { | 655 { |
613 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); | 656 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); |
614 } | 657 } |
615 | 658 |
659 LOG(INFO) << "HTTP status code " << status << " after " | |
660 << EnumerationToString(method_) << " request on: " << url_; | |
661 | |
662 if (isVerbose_) | |
663 { | |
664 LOG(INFO) << "cURL status code: " << code; | |
665 } | |
666 | |
616 CheckCode(code); | 667 CheckCode(code); |
617 | 668 |
618 if (status == 0) | 669 if (status == 0) |
619 { | 670 { |
620 // This corresponds to a call to an inexistent host | 671 // This corresponds to a call to an inexistent host |
708 #if ORTHANC_ENABLE_PKCS11 == 1 | 759 #if ORTHANC_ENABLE_PKCS11 == 1 |
709 Pkcs11::Finalize(); | 760 Pkcs11::Finalize(); |
710 #endif | 761 #endif |
711 } | 762 } |
712 | 763 |
764 | |
765 void HttpClient::SetDefaultVerbose(bool verbose) | |
766 { | |
767 GlobalParameters::GetInstance().SetDefaultVerbose(verbose); | |
768 } | |
769 | |
713 | 770 |
714 void HttpClient::SetDefaultProxy(const std::string& proxy) | 771 void HttpClient::SetDefaultProxy(const std::string& proxy) |
715 { | 772 { |
716 GlobalParameters::GetInstance().SetDefaultProxy(proxy); | 773 GlobalParameters::GetInstance().SetDefaultProxy(proxy); |
717 } | 774 } |