Mercurial > hg > orthanc
comparison OrthancFramework/Sources/HttpClient.cpp @ 4521:60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 23 Feb 2021 11:01:54 +0100 |
parents | d9473bd5ed43 |
children | 017ab543e6ef |
comparison
equal
deleted
inserted
replaced
4520:f5cb0c0ffbed | 4521:60e4f94ec30f |
---|---|
63 } | 63 } |
64 | 64 |
65 // This is a dummy wrapper function to suppress any OpenSSL-related | 65 // This is a dummy wrapper function to suppress any OpenSSL-related |
66 // problem in valgrind. Inlining is prevented. | 66 // problem in valgrind. Inlining is prevented. |
67 #if defined(__GNUC__) || defined(__clang__) | 67 #if defined(__GNUC__) || defined(__clang__) |
68 __attribute__((noinline)) | 68 __attribute__((noinline)) |
69 #endif | 69 #endif |
70 static CURLcode OrthancHttpClientPerformSSL(CURL* curl, long* status) | 70 static CURLcode OrthancHttpClientPerformSSL(CURL* curl, long* status) |
71 { | 71 { |
72 #if ORTHANC_ENABLE_SSL == 1 | 72 #if ORTHANC_ENABLE_SSL == 1 |
73 return GetHttpStatus(curl_easy_perform(curl), curl, status); | 73 return GetHttpStatus(curl_easy_perform(curl), curl, status); |
477 httpsCACertificates = httpsCACertificates_; | 477 httpsCACertificates = httpsCACertificates_; |
478 } | 478 } |
479 | 479 |
480 void SetDefaultProxy(const std::string& proxy) | 480 void SetDefaultProxy(const std::string& proxy) |
481 { | 481 { |
482 LOG(INFO) << "Setting the default proxy for HTTP client connections: " << proxy; | 482 CLOG(INFO, HTTP) << "Setting the default proxy for HTTP client connections: " << proxy; |
483 | 483 |
484 { | 484 { |
485 boost::mutex::scoped_lock lock(mutex_); | 485 boost::mutex::scoped_lock lock(mutex_); |
486 proxy_ = proxy; | 486 proxy_ = proxy; |
487 } | 487 } |
493 target = proxy_; | 493 target = proxy_; |
494 } | 494 } |
495 | 495 |
496 void SetDefaultTimeout(long seconds) | 496 void SetDefaultTimeout(long seconds) |
497 { | 497 { |
498 LOG(INFO) << "Setting the default timeout for HTTP client connections: " << seconds << " seconds"; | 498 CLOG(INFO, HTTP) << "Setting the default timeout for HTTP client connections: " << seconds << " seconds"; |
499 | 499 |
500 { | 500 { |
501 boost::mutex::scoped_lock lock(mutex_); | 501 boost::mutex::scoped_lock lock(mutex_); |
502 timeout_ = seconds; | 502 timeout_ = seconds; |
503 } | 503 } |
566 } | 566 } |
567 } | 567 } |
568 | 568 |
569 | 569 |
570 /*static int CurlDebugCallback(CURL *handle, | 570 /*static int CurlDebugCallback(CURL *handle, |
571 curl_infotype type, | 571 curl_infotype type, |
572 char *data, | 572 char *data, |
573 size_t size, | 573 size_t size, |
574 void *userptr) | 574 void *userptr) |
575 { | 575 { |
576 switch (type) | 576 switch (type) |
577 { | 577 { |
578 case CURLINFO_TEXT: | 578 case CURLINFO_TEXT: |
579 case CURLINFO_HEADER_IN: | 579 case CURLINFO_HEADER_IN: |
580 case CURLINFO_HEADER_OUT: | 580 case CURLINFO_HEADER_OUT: |
581 case CURLINFO_SSL_DATA_IN: | 581 case CURLINFO_SSL_DATA_IN: |
582 case CURLINFO_SSL_DATA_OUT: | 582 case CURLINFO_SSL_DATA_OUT: |
583 case CURLINFO_END: | 583 case CURLINFO_END: |
584 case CURLINFO_DATA_IN: | 584 case CURLINFO_DATA_IN: |
585 case CURLINFO_DATA_OUT: | 585 case CURLINFO_DATA_OUT: |
586 { | 586 { |
587 std::string s(data, size); | 587 std::string s(data, size); |
588 LOG(INFO) << "libcurl: " << s; | 588 CLOG(INFO, INFO) << "libcurl: " << s; |
589 break; | 589 break; |
590 } | 590 } |
591 | 591 |
592 default: | 592 default: |
593 break; | 593 break; |
594 } | 594 } |
595 | 595 |
596 return 0; | 596 return 0; |
597 }*/ | 597 }*/ |
598 | 598 |
785 } | 785 } |
786 | 786 |
787 | 787 |
788 bool HttpClient::ApplyInternal(CurlAnswer& answer) | 788 bool HttpClient::ApplyInternal(CurlAnswer& answer) |
789 { | 789 { |
790 CLOG(INFO, HTTP) << "New HTTP request to: " << url_ << " (timeout: " | |
791 << boost::lexical_cast<std::string>(timeout_ <= 0 ? DEFAULT_HTTP_TIMEOUT : timeout_) << "s)"; | |
792 | |
790 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); | 793 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); |
791 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, &answer)); | 794 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, &answer)); |
792 | 795 |
793 #if ORTHANC_ENABLE_SSL == 1 | 796 #if ORTHANC_ENABLE_SSL == 1 |
794 // Setup HTTPS-related options | 797 // Setup HTTPS-related options |
896 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PROXY, proxy_.c_str())); | 899 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PROXY, proxy_.c_str())); |
897 } | 900 } |
898 | 901 |
899 switch (method_) | 902 switch (method_) |
900 { | 903 { |
901 case HttpMethod_Get: | 904 case HttpMethod_Get: |
902 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); | 905 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); |
903 break; | 906 break; |
904 | 907 |
905 case HttpMethod_Post: | 908 case HttpMethod_Post: |
906 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); | 909 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); |
907 | 910 |
908 break; | 911 break; |
909 | 912 |
910 case HttpMethod_Delete: | 913 case HttpMethod_Delete: |
911 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); | 914 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); |
912 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); | 915 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); |
913 break; | 916 break; |
914 | 917 |
915 case HttpMethod_Put: | 918 case HttpMethod_Put: |
916 // http://stackoverflow.com/a/7570281/881731: Don't use | 919 // http://stackoverflow.com/a/7570281/881731: Don't use |
917 // CURLOPT_PUT if there is a body | 920 // CURLOPT_PUT if there is a body |
918 | 921 |
919 // CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); | 922 // CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); |
920 | 923 |
921 curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "PUT"); /* !!! */ | 924 curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "PUT"); /* !!! */ |
922 break; | 925 break; |
923 | 926 |
924 default: | 927 default: |
925 throw OrthancException(ErrorCode_InternalError); | 928 throw OrthancException(ErrorCode_InternalError); |
926 } | 929 } |
927 | 930 |
928 if (method_ == HttpMethod_Post || | 931 if (method_ == HttpMethod_Post || |
929 method_ == HttpMethod_Put) | 932 method_ == HttpMethod_Put) |
930 { | 933 { |
931 if (!pimpl_->userHeaders_.IsEmpty() && | 934 if (!pimpl_->userHeaders_.IsEmpty() && |
932 !pimpl_->userHeaders_.HasExpect()) | 935 !pimpl_->userHeaders_.HasExpect()) |
933 { | 936 { |
934 LOG(INFO) << "For performance, the HTTP header \"Expect\" should be set to empty string in POST/PUT requests"; | 937 CLOG(INFO, HTTP) << "For performance, the HTTP header \"Expect\" should be set to empty string in POST/PUT requests"; |
935 } | 938 } |
936 | 939 |
937 if (pimpl_->requestBody_.IsValid()) | 940 if (pimpl_->requestBody_.IsValid()) |
938 { | 941 { |
939 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_READFUNCTION, CurlRequestBody::Callback)); | 942 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_READFUNCTION, CurlRequestBody::Callback)); |
999 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); | 1002 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); |
1000 } | 1003 } |
1001 | 1004 |
1002 const boost::posix_time::ptime end = boost::posix_time::microsec_clock::universal_time(); | 1005 const boost::posix_time::ptime end = boost::posix_time::microsec_clock::universal_time(); |
1003 | 1006 |
1004 LOG(INFO) << "HTTP status code " << status << " in " | 1007 CLOG(INFO, HTTP) << "HTTP status code " << status << " in " |
1005 << ((end - start).total_milliseconds()) << " ms after " | 1008 << ((end - start).total_milliseconds()) << " ms after " |
1006 << EnumerationToString(method_) << " request on: " << url_; | 1009 << EnumerationToString(method_) << " request on: " << url_; |
1007 | 1010 |
1008 if (isVerbose_) | 1011 if (isVerbose_) |
1009 { | 1012 { |
1010 LOG(INFO) << "cURL status code: " << code; | 1013 CLOG(INFO, HTTP) << "cURL status code: " << code; |
1011 } | 1014 } |
1012 | 1015 |
1013 CheckCode(code); | 1016 CheckCode(code); |
1014 | 1017 |
1015 if (status == 0) | 1018 if (status == 0) |
1331 void HttpClient::InitializePkcs11(const std::string& module, | 1334 void HttpClient::InitializePkcs11(const std::string& module, |
1332 const std::string& pin, | 1335 const std::string& pin, |
1333 bool verbose) | 1336 bool verbose) |
1334 { | 1337 { |
1335 #if ORTHANC_ENABLE_PKCS11 == 1 | 1338 #if ORTHANC_ENABLE_PKCS11 == 1 |
1336 LOG(INFO) << "Initializing PKCS#11 using " << module | 1339 CLOG(INFO, HTTP) << "Initializing PKCS#11 using " << module |
1337 << (pin.empty() ? " (no PIN provided)" : " (PIN is provided)"); | 1340 << (pin.empty() ? " (no PIN provided)" : " (PIN is provided)"); |
1338 GlobalParameters::GetInstance().InitializePkcs11(module, pin, verbose); | 1341 GlobalParameters::GetInstance().InitializePkcs11(module, pin, verbose); |
1339 #else | 1342 #else |
1340 throw OrthancException(ErrorCode_InternalError, | 1343 throw OrthancException(ErrorCode_InternalError, |
1341 "This version of Orthanc is compiled without support for PKCS#11"); | 1344 "This version of Orthanc is compiled without support for PKCS#11"); |
1342 #endif | 1345 #endif |