1
0
mirror of synced 2025-01-18 00:56:49 +01:00

fix: Proxy not being disabled correctly when disabling it in the settings

This commit is contained in:
WerWolv 2023-11-10 21:59:20 +01:00
parent 01f7a09012
commit ec4942174b
4 changed files with 22 additions and 12 deletions

View File

@ -73,7 +73,8 @@ namespace hex {
HttpRequest& operator=(HttpRequest &&other) noexcept;
static void setProxy(std::string proxy);
static void setProxyState(bool enabled);
static void setProxyUrl(std::string proxy);
void setMethod(std::string method) {
this->m_method = std::move(method);

View File

@ -40,10 +40,14 @@ namespace hex {
});
}
void HttpRequest::setProxy(std::string proxy) {
void HttpRequest::setProxyUrl(std::string proxy) {
hex::unused(proxy);
}
void HttpRequest::setProxyState(bool state) {
hex::unused(state);
}
void HttpRequest::checkProxyErrors() { }
int HttpRequest::progressCallback(void *contents, curl_off_t dlTotal, curl_off_t dlNow, curl_off_t ulTotal, curl_off_t ulNow) {

View File

@ -5,7 +5,10 @@
namespace hex {
namespace {
std::string s_proxyUrl;
bool s_proxyState;
}
HttpRequest::HttpRequest(std::string method, std::string url) : m_method(std::move(method)), m_url(std::move(url)) {
@ -60,7 +63,9 @@ namespace hex {
curl_easy_setopt(this->m_curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(this->m_curl, CURLOPT_XFERINFODATA, this);
curl_easy_setopt(this->m_curl, CURLOPT_XFERINFOFUNCTION, progressCallback);
curl_easy_setopt(this->m_curl, CURLOPT_PROXY, s_proxyUrl.c_str());
if (s_proxyState)
curl_easy_setopt(this->m_curl, CURLOPT_PROXY, s_proxyUrl.c_str());
}
std::future<HttpRequest::Result<std::vector<u8>>> HttpRequest::downloadFile() {
@ -76,12 +81,16 @@ namespace hex {
void HttpRequest::setProxy(std::string proxy) {
void HttpRequest::setProxyUrl(std::string proxy) {
s_proxyUrl = std::move(proxy);
}
void HttpRequest::setProxyState(bool state) {
s_proxyState = state;
}
void HttpRequest::checkProxyErrors() {
if (!s_proxyUrl.empty()){
if (s_proxyState && !s_proxyUrl.empty()){
log::info("A custom proxy '{0}' is in use. Is it working correctly?", s_proxyUrl);
}
}

View File

@ -276,18 +276,14 @@ namespace hex::plugin::builtin {
/* Proxy */
HttpRequest::setProxy(ContentRegistry::Settings::read("hex.builtin.setting.proxy", "hex.builtin.setting.proxy.url", "").get<std::string>());
HttpRequest::setProxyUrl(ContentRegistry::Settings::read("hex.builtin.setting.proxy", "hex.builtin.setting.proxy.url", "").get<std::string>());
ContentRegistry::Settings::setCategoryDescription("hex.builtin.setting.proxy", "hex.builtin.setting.proxy.description");
auto proxyEnabledSetting = ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.proxy", "", "hex.builtin.setting.proxy.enable", false).setChangedCallback([](Widgets::Widget &widget) {
auto checkBox = static_cast<Widgets::Checkbox *>(&widget);
if (checkBox->isChecked()) {
HttpRequest::setProxy(ContentRegistry::Settings::read("hex.builtin.setting.proxy", "hex.builtin.setting.proxy.url", "").get<std::string>());
} else {
HttpRequest::setProxy("");
}
HttpRequest::setProxyState(checkBox->isChecked());
});
ContentRegistry::Settings::add<Widgets::TextBox>("hex.builtin.setting.proxy", "", "hex.builtin.setting.proxy.url", "")
@ -299,7 +295,7 @@ namespace hex::plugin::builtin {
.setChangedCallback([](Widgets::Widget &widget) {
auto textBox = static_cast<Widgets::TextBox *>(&widget);
HttpRequest::setProxy(textBox->getValue());
HttpRequest::setProxyUrl(textBox->getValue());
});