comparison OrthancFramework/Sources/HttpClient.cpp @ 5095:b52fe770aec0

more logs in HttpClient
author Alain Mazy <am@osimis.io>
date Wed, 12 Oct 2022 09:22:08 +0200
parents 559b35d18ef7
children 9d51c000e91a
comparison
equal deleted inserted replaced
5090:cc1a8b3ff319 5095:b52fe770aec0
44 #endif 44 #endif
45 45
46 46
47 extern "C" 47 extern "C"
48 { 48 {
49 static CURLcode GetHttpStatus(CURLcode code, CURL* curl, long* status) 49 static CURLcode GetHttpStatus(CURLcode code, CURL* curl, long* status, const std::string& url)
50 { 50 {
51 if (code == CURLE_OK) 51 if (code == CURLE_OK)
52 { 52 {
53 code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status); 53 code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status);
54 return code; 54 return code;
55 } 55 }
56 else 56 else
57 { 57 {
58 LOG(ERROR) << "Error code " << static_cast<int>(code) 58 LOG(ERROR) << "Error code " << static_cast<int>(code)
59 << " in libcurl: " << curl_easy_strerror(code); 59 << " in libcurl: " << curl_easy_strerror(code)
60 << " while accessing url: " << url;
60 *status = 0; 61 *status = 0;
61 return code; 62 return code;
62 } 63 }
63 } 64 }
64 } 65 }
66 // This is a dummy wrapper function to suppress any OpenSSL-related 67 // This is a dummy wrapper function to suppress any OpenSSL-related
67 // problem in valgrind. Inlining is prevented. 68 // problem in valgrind. Inlining is prevented.
68 #if defined(__GNUC__) || defined(__clang__) 69 #if defined(__GNUC__) || defined(__clang__)
69 __attribute__((noinline)) 70 __attribute__((noinline))
70 #endif 71 #endif
71 static CURLcode OrthancHttpClientPerformSSL(CURL* curl, long* status) 72 static CURLcode OrthancHttpClientPerformSSL(CURL* curl, long* status, const std::string& url)
72 { 73 {
73 #if ORTHANC_ENABLE_SSL == 1 74 #if ORTHANC_ENABLE_SSL == 1
74 return GetHttpStatus(curl_easy_perform(curl), curl, status); 75 return GetHttpStatus(curl_easy_perform(curl), curl, status, url);
75 #else 76 #else
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, 77 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
77 "Orthanc was compiled without SSL support, " 78 "Orthanc was compiled without SSL support, "
78 "cannot make HTTPS request"); 79 "cannot make HTTPS request");
79 #endif 80 #endif
1043 1044
1044 const boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time(); 1045 const boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time();
1045 1046
1046 if (boost::starts_with(url_, "https://")) 1047 if (boost::starts_with(url_, "https://"))
1047 { 1048 {
1048 code = OrthancHttpClientPerformSSL(pimpl_->curl_, &status); 1049 code = OrthancHttpClientPerformSSL(pimpl_->curl_, &status, url_);
1049 } 1050 }
1050 else 1051 else
1051 { 1052 {
1052 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); 1053 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status, url_);
1053 } 1054 }
1054 1055
1055 const boost::posix_time::ptime end = boost::posix_time::microsec_clock::universal_time(); 1056 const boost::posix_time::ptime end = boost::posix_time::microsec_clock::universal_time();
1056 1057
1057 CLOG(INFO, HTTP) << "HTTP status code " << status << " in " 1058 CLOG(INFO, HTTP) << "HTTP status code " << status << " in "