mirror of
https://github.com/NixOS/nix
synced 2025-07-02 13:31:48 +02:00
The short answer for why we need to do this is so we can consistently do `#include "nix/..."`. Without this change, there are ways to still make that work, but they are hacky, and they have downsides such as making it harder to make sure headers from the wrong Nix library (e..g. `libnixexpr` headers in `libnixutil`) aren't being used. The C API alraedy used `nix_api_*`, so its headers are *not* put in subdirectories accordingly. Progress on #7876 We resisted doing this for a while because it would be annoying to not have the header source file pairs close by / easy to change file path/name from one to the other. But I am ameliorating that with symlinks in the next commit.
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#include "nix/network-proxy.hh"
|
|
|
|
#include <algorithm>
|
|
|
|
#include "nix/environment-variables.hh"
|
|
|
|
namespace nix {
|
|
|
|
static const StringSet lowercaseVariables{"http_proxy", "https_proxy", "ftp_proxy", "all_proxy", "no_proxy"};
|
|
|
|
static StringSet getAllVariables()
|
|
{
|
|
StringSet variables = lowercaseVariables;
|
|
for (const auto & variable : lowercaseVariables) {
|
|
std::string upperVariable;
|
|
std::transform(
|
|
variable.begin(), variable.end(), upperVariable.begin(), [](unsigned char c) { return std::toupper(c); });
|
|
variables.insert(std::move(upperVariable));
|
|
}
|
|
return variables;
|
|
}
|
|
|
|
const StringSet networkProxyVariables = getAllVariables();
|
|
|
|
static StringSet getExcludingNoProxyVariables()
|
|
{
|
|
static const StringSet excludeVariables{"no_proxy", "NO_PROXY"};
|
|
StringSet variables;
|
|
std::set_difference(
|
|
networkProxyVariables.begin(),
|
|
networkProxyVariables.end(),
|
|
excludeVariables.begin(),
|
|
excludeVariables.end(),
|
|
std::inserter(variables, variables.begin()));
|
|
return variables;
|
|
}
|
|
|
|
static const StringSet excludingNoProxyVariables = getExcludingNoProxyVariables();
|
|
|
|
bool haveNetworkProxyConnection()
|
|
{
|
|
for (const auto & variable : excludingNoProxyVariables) {
|
|
if (getEnv(variable).has_value()) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|