Fix handling proxy configuration

This commit is contained in:
Bartosz Wieczorek 2025-07-18 12:27:07 +02:00
parent 406b9ff97c
commit b6211d94f8

View File

@ -1,5 +1,6 @@
#pragma once
#include <algorithm>
#include <rublon/error.hpp>
#include <rublon/memory.hpp>
#include <rublon/static_string.hpp>
@ -86,6 +87,7 @@ class ConfigurationReader {
if(it == keyValues.end()) {
return std::nullopt;
}
return string{it->second.data(), it->second.size(), memoryResource};
};
@ -198,6 +200,12 @@ class ConfigurationReader {
return true;
};
auto toLowerCaseOpt = [](auto str) {
if(str)
std::transform(str->cbegin(), str->cend(), str->begin(), [](auto c) { return std::tolower(c); });
return str;
};
/// NOTE:
// getStringOpt can return a valid empty string, for example configuration entry like
// option=
@ -238,8 +246,8 @@ class ConfigurationReader {
// reading proxy configuration
config.proxyEnabled = getBool("proxyEnabled").value_or(false);
config.proxyType = getStringOpt("proxyType");
config.proxyHost = getStringOpt("proxyHost");
config.proxyType = toLowerCaseOpt(getStringOpt("proxyType"));
config.proxyHost = toLowerCaseOpt(getStringOpt("proxyHost"));
// Apply fallback if no config is set
if(config.proxyEnabled && (!config.proxyType || config.proxyType->empty()) && (!config.proxyHost || config.proxyHost->empty())) {