1 | #include "cpr/response.h" |
2 | |
3 | namespace cpr { |
4 | |
5 | Response::Response(std::shared_ptr<CurlHolder> curl, std::string&& p_text, std::string&& , Cookies&& p_cookies = Cookies{}, Error&& p_error = Error{}) : curl_(std::move(curl)), text(std::move(p_text)), cookies(std::move(p_cookies)), error(std::move(p_error)), raw_header(std::move(p_header_string)) { |
6 | header = cpr::util::parseHeader(headers: raw_header, status_line: &status_line, reason: &reason); |
7 | assert(curl_); |
8 | assert(curl_->handle); |
9 | curl_easy_getinfo(curl_->handle, CURLINFO_RESPONSE_CODE, &status_code); |
10 | curl_easy_getinfo(curl_->handle, CURLINFO_TOTAL_TIME, &elapsed); |
11 | char* url_string{nullptr}; |
12 | curl_easy_getinfo(curl_->handle, CURLINFO_EFFECTIVE_URL, &url_string); |
13 | url = Url(url_string); |
14 | #if LIBCURL_VERSION_NUM >= 0x073700 |
15 | curl_easy_getinfo(curl_->handle, CURLINFO_SIZE_DOWNLOAD_T, &downloaded_bytes); |
16 | curl_easy_getinfo(curl_->handle, CURLINFO_SIZE_UPLOAD_T, &uploaded_bytes); |
17 | #else |
18 | double downloaded_bytes_double, uploaded_bytes_double; |
19 | curl_easy_getinfo(curl_->handle, CURLINFO_SIZE_DOWNLOAD, &downloaded_bytes_double); |
20 | curl_easy_getinfo(curl_->handle, CURLINFO_SIZE_UPLOAD, &uploaded_bytes_double); |
21 | downloaded_bytes = downloaded_bytes_double; |
22 | uploaded_bytes = uploaded_bytes_double; |
23 | #endif |
24 | curl_easy_getinfo(curl_->handle, CURLINFO_REDIRECT_COUNT, &redirect_count); |
25 | } |
26 | |
27 | std::vector<CertInfo> Response::GetCertInfos() { |
28 | assert(curl_); |
29 | assert(curl_->handle); |
30 | curl_certinfo* ci{nullptr}; |
31 | curl_easy_getinfo(curl_->handle, CURLINFO_CERTINFO, &ci); |
32 | |
33 | std::vector<CertInfo> cert_infos; |
34 | for (int i = 0; i < ci->num_of_certs; i++) { |
35 | CertInfo cert_info; |
36 | // NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic) |
37 | for (curl_slist* slist = ci->certinfo[i]; slist; slist = slist->next) { |
38 | cert_info.emplace_back(str: std::string{slist->data}); |
39 | } |
40 | cert_infos.emplace_back(args&: cert_info); |
41 | } |
42 | return cert_infos; |
43 | } |
44 | } // namespace cpr |
45 | |