Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add http_proxy environment variable support for Windows #29371

Closed
ctaggart opened this issue Apr 25, 2019 · 3 comments · Fixed by dotnet/corefx#37238
Closed

Add http_proxy environment variable support for Windows #29371

ctaggart opened this issue Apr 25, 2019 · 3 comments · Fixed by dotnet/corefx#37238
Assignees
Milestone

Comments

@ctaggart
Copy link
Contributor

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:

@davidsh
Copy link
Contributor

davidsh commented Apr 25, 2019

This is part of my current plan.

See: dotnet/corefx#36177 (comment)

@davidsh davidsh self-assigned this Apr 25, 2019
@davidsh davidsh changed the title add http_proxy environment variable support for Windows Add http_proxy environment variable support for Windows Apr 25, 2019
davidsh referenced this issue in davidsh/corefx Apr 25, 2019
This is a redo of PR dotnet#35887.

Added support for uppercase HTTP_PROXY and NO_PROXY environment variables.
The uppercase versions are being used by Docker and other tools. This now
completes the set of environment variables that are already handling both
lower and upper case variants.

Note: This HttpEnvironmentProxy class is currently only used on Linux and OSX.
It is not used on Windows yet. I do plan to add support for this to Windows
at a later time, see #37187.

Added detection of CGI environments in order to suppress using the uppercase
HTTP_PROXY environment variable. See https://httpoxy.org/

Fixed some typos in the CSPROJ of the Http Unit Tests.
davidsh referenced this issue in dotnet/corefx Apr 26, 2019
This is a redo of PR #35887.

Added support for uppercase HTTP_PROXY and NO_PROXY environment variables.
The uppercase versions are being used by Docker and other tools. This now
completes the set of environment variables that are already handling both
lower and upper case variants.

Note: This HttpEnvironmentProxy class is currently only used on Linux and OSX.
It is not used on Windows yet. I do plan to add support for this to Windows
at a later time, see #37187.

Added detection of CGI environments in order to suppress using the uppercase
HTTP_PROXY environment variable. See https://httpoxy.org/

Fixed some typos in the CSPROJ of the Http Unit Tests.
davidsh referenced this issue in davidsh/corefx Apr 27, 2019
Changed the Windows version of SocketsHttpHandler so that it will honor the same environment
variables similar to the Linux and OSX versions. If the environment variables are not set
then it reverts back to the Windows WinInet/IE settings behavior.

I added several kinds of unit and end-to-end tests to verify the SystemProxyInfo class is
making the correct choice for all the different platforms regarding whether the
HttpEnvironmentProxy or platform proxy (HttpSystemProxy for Windows and MacProxy for OSX)
is used.

Fixes #37187
davidsh referenced this issue in davidsh/corefx Apr 27, 2019
Changed the Windows version of SocketsHttpHandler so that it will honor the same environment
variables similar to the Linux and OSX versions. If the environment variables are not set
then it reverts back to the Windows WinInet/IE settings behavior.

I added several kinds of unit and end-to-end tests to verify the SystemProxyInfo class is
making the correct choice for all the different platforms regarding whether the
HttpEnvironmentProxy or platform proxy (HttpSystemProxy for Windows and MacProxy for OSX)
is used.

Fixes #37187
davidsh referenced this issue in davidsh/corefx Apr 27, 2019
Changed the Windows version of SocketsHttpHandler so that it will honor the same environment
variables similar to the Linux and OSX versions. If the environment variables are not set
then it reverts back to the Windows WinInet/IE settings behavior.

I added several kinds of unit and end-to-end tests to verify the SystemProxyInfo class is
making the correct choice for all the different platforms regarding whether the
HttpEnvironmentProxy or platform proxy (HttpSystemProxy for Windows and MacProxy for OSX)
is used.

Fixes #37187
davidsh referenced this issue in dotnet/corefx Apr 28, 2019
Changed the Windows version of SocketsHttpHandler so that it will honor the same environment
variables similar to the Linux and OSX versions. If the environment variables are not set
then it reverts back to the Windows WinInet/IE settings behavior.

I added several kinds of unit and end-to-end tests to verify the SystemProxyInfo class is
making the correct choice for all the different platforms regarding whether the
HttpEnvironmentProxy or platform proxy (HttpSystemProxy for Windows and MacProxy for OSX)
is used.

Fixes #37187
@JanosPalinkas
Copy link

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

@scalablecory
Copy link
Contributor

@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)

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants