adapt and set proper Fix curl deprecation warnings
* now curls still can be 7.19 and if 7.56.0 is detected then we used multipart
* commit 99209cd5d7
This commit is contained in:
parent
b7ad037647
commit
005debcd8a
@ -215,26 +215,26 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CurlHandlePool *pool;
|
CurlHandlePool *pool;
|
||||||
CURL *curl;
|
CURL *curl = nullptr;
|
||||||
CURLM *multi;
|
CURLM *multi = nullptr;
|
||||||
HTTPFetchRequest request;
|
HTTPFetchRequest request;
|
||||||
HTTPFetchResult result;
|
HTTPFetchResult result;
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
struct curl_slist *http_header;
|
struct curl_slist *http_header = nullptr;
|
||||||
curl_httppost *post;
|
#if LIBCURL_VERSION_NUM >= 0x075500
|
||||||
|
curl_mime *multipart_mime = nullptr;
|
||||||
|
#elif LIBCURL_VERSION_NUM >= 0x071304
|
||||||
|
curl_httppost *post = nullptr;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
|
HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
|
||||||
CurlHandlePool *pool_):
|
CurlHandlePool *pool_):
|
||||||
pool(pool_),
|
pool(pool_),
|
||||||
curl(NULL),
|
|
||||||
multi(NULL),
|
|
||||||
request(request_),
|
request(request_),
|
||||||
result(request_),
|
result(request_),
|
||||||
oss(std::ios::binary),
|
oss(std::ios::binary)
|
||||||
http_header(NULL),
|
|
||||||
post(NULL)
|
|
||||||
{
|
{
|
||||||
curl = pool->alloc();
|
curl = pool->alloc();
|
||||||
if (curl == NULL) {
|
if (curl == NULL) {
|
||||||
@ -257,15 +257,16 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
|
|||||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LIBCURL_VERSION_NUM >= 0x071304
|
|
||||||
// Restrict protocols so that curl vulnerabilities in
|
// Restrict protocols so that curl vulnerabilities in
|
||||||
// other protocols don't affect us.
|
// other protocols don't affect us.
|
||||||
// These settings were introduced in curl 7.19.4.
|
#if LIBCURL_VERSION_NUM >= 0x075500
|
||||||
long protocols =
|
// These settings were introduced in curl 7.85.0.
|
||||||
CURLPROTO_HTTP |
|
const char *protocols = "HTTP,HTTPS,FTP,FTPS";
|
||||||
CURLPROTO_HTTPS |
|
curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, protocols);
|
||||||
CURLPROTO_FTP |
|
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, protocols);
|
||||||
CURLPROTO_FTPS;
|
#elif LIBCURL_VERSION_NUM >= 0x071304
|
||||||
|
// These settings were introduced in curl 7.19.4, and later deprecated.
|
||||||
|
long protocols = CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FTP | CURLPROTO_FTPS;
|
||||||
curl_easy_setopt(curl, CURLOPT_PROTOCOLS, protocols);
|
curl_easy_setopt(curl, CURLOPT_PROTOCOLS, protocols);
|
||||||
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, protocols);
|
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, protocols);
|
||||||
#endif
|
#endif
|
||||||
@ -296,6 +297,15 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
|
|||||||
|
|
||||||
// Set data from fields or raw_data
|
// Set data from fields or raw_data
|
||||||
if (request.multipart) {
|
if (request.multipart) {
|
||||||
|
#if LIBCURL_VERSION_NUM >= 0x075500
|
||||||
|
multipart_mime = curl_mime_init(curl);
|
||||||
|
for (auto &it : request.fields) {
|
||||||
|
curl_mimepart *part = curl_mime_addpart(multipart_mime);
|
||||||
|
curl_mime_name(part, it.first.c_str());
|
||||||
|
curl_mime_data(part, it.second.c_str(), it.second.size());
|
||||||
|
}
|
||||||
|
curl_easy_setopt(curl, CURLOPT_MIMEPOST, multipart_mime);
|
||||||
|
#elif LIBCURL_VERSION_NUM >= 0x071304
|
||||||
curl_httppost *last = NULL;
|
curl_httppost *last = NULL;
|
||||||
for (StringMap::iterator it = request.fields.begin();
|
for (StringMap::iterator it = request.fields.begin();
|
||||||
it != request.fields.end(); ++it) {
|
it != request.fields.end(); ++it) {
|
||||||
@ -307,8 +317,8 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
|
|||||||
CURLFORM_END);
|
CURLFORM_END);
|
||||||
}
|
}
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
|
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
|
||||||
// request.post_fields must now *never* be
|
// request.post_fields must now *never* be modified until CURLOPT_HTTPPOST is cleared
|
||||||
// modified until CURLOPT_HTTPPOST is cleared
|
#endif
|
||||||
} else {
|
} else {
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
case HTTP_GET:
|
case HTTP_GET:
|
||||||
@ -423,11 +433,17 @@ HTTPFetchOngoing::~HTTPFetchOngoing()
|
|||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
|
||||||
curl_slist_free_all(http_header);
|
curl_slist_free_all(http_header);
|
||||||
}
|
}
|
||||||
|
#if LIBCURL_VERSION_NUM >= 0x075500
|
||||||
|
if (multipart_mime) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_MIMEPOST, nullptr);
|
||||||
|
curl_mime_free(multipart_mime);
|
||||||
|
}
|
||||||
|
#elif LIBCURL_VERSION_NUM >= 0x071304
|
||||||
if (post) {
|
if (post) {
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, NULL);
|
curl_easy_setopt(curl, CURLOPT_HTTPPOST, NULL);
|
||||||
curl_formfree(post);
|
curl_formfree(post);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
// Store the cURL handle for reuse
|
// Store the cURL handle for reuse
|
||||||
pool->free(curl);
|
pool->free(curl);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user