Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cpr/response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ Response::Response(std::shared_ptr<CurlHolder> curl, std::string&& p_text, std::
uploaded_bytes = uploaded_bytes_double;
#endif
curl_easy_getinfo(curl_->handle, CURLINFO_REDIRECT_COUNT, &redirect_count);
#if LIBCURL_VERSION_NUM >= 0x071300 // 7.19.0
char* ip_ptr{nullptr};
if (curl_easy_getinfo(curl_->handle, CURLINFO_PRIMARY_IP, &ip_ptr) == CURLE_OK && ip_ptr) {
primary_ip = ip_ptr;
}
#endif
#if LIBCURL_VERSION_NUM >= 0x071500 // 7.21.0
// Ignored here since libcurl uses a long for this.
// NOLINTNEXTLINE(google-runtime-int)
long port = 0;
if (curl_easy_getinfo(curl_->handle, CURLINFO_PRIMARY_PORT, &port) == CURLE_OK) {
primary_port = port;
}
#endif
}

std::vector<CertInfo> Response::GetCertInfos() const {
Expand Down
2 changes: 2 additions & 0 deletions include/cpr/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Response {
// Ignored here since libcurl uses a long for this.
// NOLINTNEXTLINE(google-runtime-int)
long redirect_count{};
std::string primary_ip{};
std::uint16_t primary_port{};

Response() = default;
Response(std::shared_ptr<CurlHolder> curl, std::string&& p_text, std::string&& p_header_string, Cookies&& p_cookies, Error&& p_error);
Expand Down
2 changes: 2 additions & 0 deletions test/async_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ TEST(AsyncTests, AsyncGetTest) {
EXPECT_EQ(url, response.url);
EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
EXPECT_EQ(200, response.status_code);
EXPECT_EQ(response.primary_ip, "127.0.0.1");
EXPECT_EQ(response.primary_port, server->GetPort());
}

TEST(AsyncTests, AsyncGetMultipleTest) {
Expand Down
Loading