Skip to content
Merged
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
25 changes: 14 additions & 11 deletions src/UtilHTTPClient_libcurl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ class CUtilHTTPResponse : public IUtilHTTPResponse
{
m_pResponsePayload->Finalize();

auto code = curl_easy_getinfo(m_CurlEasyHandle, CURLINFO_RESPONSE_CODE, &m_iResponseStatusCode);
// CURLINFO_RESPONSE_CODE 写入的是 long:在 long 为 8 字节的平台上直接传 &m_iResponseStatusCode 会改写相邻成员
long responseCode{};
auto code = curl_easy_getinfo(m_CurlEasyHandle, CURLINFO_RESPONSE_CODE, &responseCode);
m_iResponseStatusCode = static_cast<int>(responseCode);

// 优先使用 curl 结果码判断网络层错误
if (curlResult != CURLE_OK)
Expand Down Expand Up @@ -502,9 +505,9 @@ class CUtilHTTPRequest : public IUtilHTTPRequest
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_WRITEDATA, this);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_HEADERFUNCTION, WriteHeaderCallback);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_HEADERDATA, this);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_CONNECTTIMEOUT_MS, 60000);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_TIMEOUT_MS, 60000);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_CONNECTTIMEOUT_MS, 60000L);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_TIMEOUT_MS, 60000L);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_ACCEPT_ENCODING, "");
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_COOKIEFILE, "");
if (m_CurlCookieHandle)
Expand Down Expand Up @@ -699,13 +702,13 @@ class CUtilHTTPRequest : public IUtilHTTPRequest

void SetTimeout(int secs) override
{
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_TIMEOUT_MS, secs * 1000);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_CONNECTTIMEOUT_MS, secs * 1000);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_TIMEOUT_MS, secs * 1000L);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_CONNECTTIMEOUT_MS, secs * 1000L);
}

void SetPostBody(const char* contentType, const char* payload, size_t payloadSize) override
{
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_POSTFIELDSIZE, payloadSize);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_POSTFIELDSIZE, static_cast<long>(payloadSize));
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_COPYPOSTFIELDS, payload);

if (contentType && contentType[0])
Expand All @@ -723,13 +726,13 @@ class CUtilHTTPRequest : public IUtilHTTPRequest
{
if (b)
{
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_SSL_VERIFYHOST, 2);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_SSL_VERIFYHOST, 2L);
}
else
{
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(m_CurlEasyHandle, CURLOPT_SSL_VERIFYHOST, 0L);
}
}

Expand Down
Loading