Runtime: Add http_proxy environment variable support for Windows

Created on 25 Apr 2019  路  3Comments  路  Source: dotnet/runtime

In AnyUnix environments, setting a proxy is as easy as:

http_proxy=http://localhost:8080 dotnet run

Or

export http_proxy=http://localhost:8080
dotnet run

On Windows, I want the same capability:

$env:http_proxy="http://localhost:8080"
dotnet run

Unfortunately, that does not work. Here is the test code to explain:

        [OuterLoop("Uses external server")]
        [PlatformSpecific(TestPlatforms.AnyUnix)] // The default proxy is resolved via WinINet on Windows.
        [Fact]
        public async Task ProxySetViaEnvironmentVariable_DefaultProxyCredentialsUsed()
        {
            var cred = new NetworkCredential(Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"));
            LoopbackServer.Options options =
                new LoopbackServer.Options { IsProxy = true, Username = cred.UserName, Password = cred.Password };

            await LoopbackServer.CreateServerAsync(async (proxyServer, proxyUri) =>
            {
                // HttpWebRequest/HttpClient will read a default proxy from the http_proxy environment variable. Ensure
                // that when it does our default proxy credentials are used. To avoid messing up anything else in this
                // process we run the test in another process.

Can you please add support for http_proxy environment variables on Windows too and then fall back to the WinINet? I don't want to change my system configuration when I just need to proxy a single app or a few dotnet runs.

Here is a related issue, but not the same:

area-System.Net.Http

Most helpful comment

@joaoattila you have system-wide envvars, but you also scope it down. e.g. in console:

set HTTP_PROXY=http://foo
dotnet run

This will only apply the variable to apps launched from that console.

(also, commenting on old closed issues is a gamble because we don't actively monitor things once they're closed -- please open new issues in the future, or ask on Stack Overflow)

All 3 comments

This is part of my current plan.

See: https://github.com/dotnet/corefx/pull/36177#issuecomment-475694415

How can I set the HTTP_PROXY only for a specific .NET Core 3 application? If I set an environment variable there it goes to all other applications too right? Couldn't find any documentation how to set it into appsettings.json as .NET Framework does with Web.config. @davidsh

@joaoattila you have system-wide envvars, but you also scope it down. e.g. in console:

set HTTP_PROXY=http://foo
dotnet run

This will only apply the variable to apps launched from that console.

(also, commenting on old closed issues is a gamble because we don't actively monitor things once they're closed -- please open new issues in the future, or ask on Stack Overflow)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jzabroski picture jzabroski  路  3Comments

EgorBo picture EgorBo  路  3Comments

chunseoklee picture chunseoklee  路  3Comments

GitAntoinee picture GitAntoinee  路  3Comments

jamesqo picture jamesqo  路  3Comments