mirror of
https://github.com/NixOS/nix
synced 2025-07-05 20:41:47 +02:00
Honor the same set of proxy environment variables (#10611)
Different parts of the project honor different sets of proxy environment variables. With this commit all parts of the project will honor the same set of proxy environment variables. --------- Co-authored-by: Your Name <you@example.com> Co-authored-by: John Ericson <John.Ericson@Obsidian.Systems>
This commit is contained in:
parent
da3381d51f
commit
b4950404ba
8 changed files with 76 additions and 25 deletions
45
src/libcmd/network-proxy.cc
Normal file
45
src/libcmd/network-proxy.cc
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "network-proxy.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "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) {
|
||||
variables.insert(boost::to_upper_copy(variable));
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue