Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a9e01da

Browse files
authored
Fix ServicePointManager.ProxyAddressIfNecessary to ignore "system" proxy failures (#26925)
The whole ServicePointManager implementation is there just to make basic stuff not fail. But HttpWebRequest's Proxy defaults to an internal dummy singleton SystemWebProxy whose GetProxy method throws a PlatformNotSupportedException. Until we can clean that up and have a real proxy in place, we should just eat that PlatformNotSupportedException when the ServicePointManager calls GetProxy.
1 parent 1a5cdbe commit a9e01da

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/System.Net.Requests/tests/HttpWebRequestTest.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -682,14 +682,7 @@ public void ContinueDelegate_SetDelegateThenGet_ValuesSame(Uri remoteServer)
682682
public void ServicePoint_GetValue_ExpectedResult(Uri remoteServer)
683683
{
684684
HttpWebRequest request = WebRequest.CreateHttp(remoteServer);
685-
if (PlatformDetection.IsFullFramework)
686-
{
687-
Assert.NotNull(request.ServicePoint);
688-
}
689-
else
690-
{
691-
Assert.Throws<PlatformNotSupportedException>(() => request.ServicePoint);
692-
}
685+
Assert.NotNull(request.ServicePoint);
693686
}
694687

695688
[Theory, MemberData(nameof(EchoServers))]

src/System.Net.ServicePoint/src/System/Net/ServicePointManager.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,27 @@ private static bool ProxyAddressIfNecessary(ref Uri address, IWebProxy proxy)
176176
{
177177
if (proxy != null && !address.IsLoopback)
178178
{
179-
Uri proxyAddress = proxy.GetProxy(address);
180-
if (proxyAddress != null)
179+
try
181180
{
182-
if (proxyAddress.Scheme != Uri.UriSchemeHttp)
181+
Uri proxyAddress = proxy.GetProxy(address);
182+
if (proxyAddress != null)
183183
{
184-
throw new NotSupportedException(SR.Format(SR.net_proxyschemenotsupported, address.Scheme));
185-
}
184+
if (proxyAddress.Scheme != Uri.UriSchemeHttp)
185+
{
186+
throw new NotSupportedException(SR.Format(SR.net_proxyschemenotsupported, address.Scheme));
187+
}
186188

187-
address = proxyAddress;
188-
return true;
189+
address = proxyAddress;
190+
return true;
191+
}
192+
}
193+
catch (PlatformNotSupportedException)
194+
{
195+
// HttpWebRequest has a dummy SystemWebProxy that's used as a sentinel
196+
// and whose GetProxy method throws a PlatformNotSupportedException.
197+
// For the purposes of this stand-in ServicePointManager implementation,
198+
// we ignore this default "system" proxy for the purposes of mapping
199+
// to a particular ServicePoint instance.
189200
}
190201
}
191202

0 commit comments

Comments
 (0)