1
0
mirror of https://github.com/luanti-org/luanti.git synced 2026-01-12 12:15:26 +01:00

Fix resetting some curl options at runtime

This commit is contained in:
sfan5
2026-01-09 12:49:13 +01:00
committed by SmallJoker
parent cf39065511
commit b98afa6e9a

View File

@@ -219,19 +219,18 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
return;
// Set static cURL options
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, CURLFOLLOW_ALL);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L);
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); // = all supported ones
std::string bind_address = g_settings->get("bind_address");
if (!bind_address.empty()) {
curl_easy_setopt(curl, CURLOPT_INTERFACE, bind_address.c_str());
}
curl_easy_setopt(curl, CURLOPT_INTERFACE,
bind_address.empty() ? nullptr : bind_address.c_str());
if (!g_settings->getBool("enable_ipv6")) {
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
bool enable_ipv6 = g_settings->getBool("enable_ipv6");
curl_easy_setopt(curl, CURLOPT_IPRESOLVE,
enable_ipv6 ? CURL_IPRESOLVE_WHATEVER : CURL_IPRESOLVE_V4);
// Restrict protocols so that curl vulnerabilities in
// other protocols don't affect us.
@@ -259,8 +258,8 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS,
request.connect_timeout);
if (!request.useragent.empty())
curl_easy_setopt(curl, CURLOPT_USERAGENT, request.useragent.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT,
request.useragent.empty() ? nullptr : request.useragent.c_str());
// Set up a write callback that writes to the
// result struct, unless the data is to be discarded
@@ -279,14 +278,14 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
default:
assert(false);
case HTTP_GET:
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
break;
case HTTP_HEAD:
// This is kinda pointless right now, since we don't return response headers (TODO?)
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
break;
case HTTP_POST:
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
break;
case HTTP_PUT:
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
@@ -338,9 +337,8 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_header);
if (!g_settings->getBool("curl_verify_cert")) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
}
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER,
g_settings->getBool("curl_verify_cert") ? 1L : 0L);
}
CURLcode HTTPFetchOngoing::start(CURLM *multi_)
@@ -414,7 +412,6 @@ HTTPFetchOngoing::~HTTPFetchOngoing()
// Set safe options for the reusable cURL handle
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
httpfetch_discardfunction);
curl_easy_setopt(curl, CURLOPT_USERAGENT, nullptr);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, nullptr);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, nullptr);