Make WebRequest.GetSystemWebProxy() return a working proxy (dotnet/corefx#41692)
authorStephen Toub <stoub@microsoft.com>
Sat, 12 Oct 2019 12:15:05 +0000 (08:15 -0400)
committerGitHub <noreply@github.com>
Sat, 12 Oct 2019 12:15:05 +0000 (08:15 -0400)
commit48c5afd0e5834f928ac4dc17fd994ba733d3a05f
treed658be87033eba258b1d327c1097bb9f46b06d69
parenta00aafc5a603913180c49f2fc39a3cdb721fadf0
Make WebRequest.GetSystemWebProxy() return a working proxy (dotnet/corefx#41692)

* Make WebRequest.GetSystemWebProxy() return a working proxy

Today it returns a singleton on .NET Core that throws PlatformNotSupportedExceptions, and is only used for its reference identity by the WebRequest implementation.  This is problematic for existing code that's taking this proxy and passing it to, for example, ClientWebSocket's Proxy, as it will end up being an expensive nop.  In fact, there's currently no way when targeting netstandard2.0 to tell ClientWebSocket to use a default proxy.

With this fix, WebRequest.DefaultWebProxy (which just defaults to GetSystemWebProxy()) will now return HttpClient.DefaultProxy, which is actually a working proxy implementation.

* Stop throwing NotSupportedException from HttpClient.DefaultProxy.set_Credentials

The OS and how the environment is configured determines what concrete type is returned from HttpClient's DefaultProxy property.  And currently these different types behave differently from set_Credentials.  Two of them are throwing NotSupportedException, which is not expected from the IWebProxy interface.  We should just roundtrip the credentials set, even if they're not used.

Commit migrated from https://github.com/dotnet/corefx/commit/8d21b79b924d29088dbde46d42737a657d466b5e
src/libraries/System.Net.Http/src/System.Net.Http.csproj
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpEnvironmentProxy.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/MacProxy.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SystemProxyInfo.uap.cs
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.netcoreapp.cs
src/libraries/System.Net.Requests/src/System.Net.Requests.csproj
src/libraries/System.Net.Requests/src/System/Net/SystemWebProxy.cs [deleted file]
src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs