Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ System.Net.Http.WinHttpHandler</PackageDescription>
Link="Common\System\Net\UriScheme.cs" />
<Compile Include="$(CommonPath)\System\Net\Http\HttpHandlerDefaults.cs"
Link="Common\System\Net\Http\HttpHandlerDefaults.cs" />
<Compile Include="$(CommonPath)\System\Net\Http\WinInetProxyHelper.cs"
Link="Common\System\Net\Http\WinInetProxyHelper.cs" />
<Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.cs"
Link="Common\System\Net\Security\CertificateHelper.cs" />
<Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.Windows.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class WinHttpHandler : HttpMessageHandler

private readonly object _lockObject = new object();
private bool _doManualDecompressionCheck;
private WinInetProxyHelper? _proxyHelper;
private bool _automaticRedirection = HttpHandlerDefaults.DefaultAutomaticRedirection;
private int _maxAutomaticRedirections = HttpHandlerDefaults.DefaultMaxAutomaticRedirections;
private DecompressionMethods _automaticDecompression = HttpHandlerDefaults.DefaultAutomaticDecompression;
Expand Down Expand Up @@ -814,29 +813,7 @@ private void EnsureSessionHandleExists(WinHttpRequestState state)
Interop.WinHttp.WINHTTP_NO_PROXY_NAME,
Interop.WinHttp.WINHTTP_NO_PROXY_BYPASS,
(int)Interop.WinHttp.WINHTTP_FLAG_ASYNC);

if (sessionHandle.IsInvalid)
{
int lastError = Marshal.GetLastWin32Error();
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(this, $"error={lastError}");

if (lastError != Interop.WinHttp.ERROR_INVALID_PARAMETER)
{
ThrowOnInvalidHandle(sessionHandle, nameof(Interop.WinHttp.WinHttpOpen));
}

// We must be running on a platform earlier than Win8.1/Win2K12R2 which doesn't support
// WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY. So, we'll need to read the Wininet style proxy
// settings ourself using our WinInetProxyHelper object.
_proxyHelper = new WinInetProxyHelper();
sessionHandle = Interop.WinHttp.WinHttpOpen(
IntPtr.Zero,
_proxyHelper.ManualSettingsOnly ? Interop.WinHttp.WINHTTP_ACCESS_TYPE_NAMED_PROXY : Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY,
_proxyHelper.ManualSettingsOnly ? _proxyHelper.Proxy : Interop.WinHttp.WINHTTP_NO_PROXY_NAME,
_proxyHelper.ManualSettingsOnly ? _proxyHelper.ProxyBypass : Interop.WinHttp.WINHTTP_NO_PROXY_BYPASS,
(int)Interop.WinHttp.WINHTTP_FLAG_ASYNC);
ThrowOnInvalidHandle(sessionHandle, nameof(Interop.WinHttp.WinHttpOpen));
}
ThrowOnInvalidHandle(sessionHandle, nameof(Interop.WinHttp.WinHttpOpen));

uint optionAssuredNonBlockingTrue = 1; // TRUE

Expand Down Expand Up @@ -1282,17 +1259,15 @@ private void SetRequestHandleOptions(WinHttpRequestState state)
SetRequestHandleHttp2Options(state.RequestHandle, state.RequestMessage.Version);
}

private void SetRequestHandleProxyOptions(WinHttpRequestState state)
private static void SetRequestHandleProxyOptions(WinHttpRequestState state)
{
Debug.Assert(state.RequestMessage != null);
Debug.Assert(state.RequestMessage.RequestUri != null);
Debug.Assert(state.RequestHandle != null);

// We've already set the proxy on the session handle if we're using no proxy or default proxy settings.
// We only need to change it on the request handle if we have a specific IWebProxy or need to manually
// implement Wininet-style auto proxy detection.
if (state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.UseCustomProxy ||
state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.UseWinInetProxy)
// We've already set the proxy on the session handle if we're using no proxy or default/auto proxy settings.
Comment thread
ManickaP marked this conversation as resolved.
// We only need to change it on the request handle if we have a specific custom IWebProxy.
if (state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.UseCustomProxy)
{
Interop.WinHttp.WINHTTP_PROXY_INFO proxyInfo = default;
bool updateProxySettings = false;
Expand All @@ -1302,7 +1277,6 @@ private void SetRequestHandleProxyOptions(WinHttpRequestState state)
{
if (state.Proxy != null)
{
Debug.Assert(state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.UseCustomProxy);
updateProxySettings = true;

Uri? proxyUri = state.Proxy.IsBypassed(uri) ? null : state.Proxy.GetProxy(uri);
Expand All @@ -1317,13 +1291,6 @@ private void SetRequestHandleProxyOptions(WinHttpRequestState state)
proxyInfo.Proxy = Marshal.StringToHGlobalUni(proxyString);
}
}
else if (_proxyHelper != null && _proxyHelper.AutoSettingsUsed)
{
if (_proxyHelper.GetProxyForUrl(_sessionHandle, uri, out proxyInfo))
{
updateProxySettings = true;
}
}

if (updateProxySettings)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ public static SafeWinHttpHandle WinHttpOpen(
return new FakeSafeWinHttpHandle(false);
}

if (accessType == Interop.WinHttp.WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY &&
!TestControl.WinHttpAutomaticProxySupport)
{
TestControl.LastWin32Error = (int)Interop.WinHttp.ERROR_INVALID_PARAMETER;
return new FakeSafeWinHttpHandle(false);
}

APICallHistory.ProxyInfo proxyInfo;
proxyInfo.AccessType = accessType;
proxyInfo.Proxy = proxyName;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
Link="Common\System\Net\UriScheme.cs" />
<Compile Include="$(CommonPath)System\Net\Http\HttpHandlerDefaults.cs"
Link="Common\System\Net\Http\HttpHandlerDefaults.cs" />
<Compile Include="$(CommonPath)\System\Net\Http\WinInetProxyHelper.cs"
Link="Common\System\Net\Http\WinInetProxyHelper.cs" />
<Compile Include="$(CommonPath)System\Net\Security\CertificateHelper.cs"
Link="Common\System\Net\Security\CertificateHelper.cs" />
<Compile Include="$(CommonPath)System\Net\Security\CertificateHelper.Windows.cs"
Expand Down Expand Up @@ -86,8 +84,6 @@
Link="ProductionCode\WinHttpTrailersHelper.cs" />
<Compile Include="..\..\src\System\Net\Http\WinHttpTransportContext.cs"
Link="ProductionCode\WinHttpTransportContext.cs" />
<Compile Include="..\..\..\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\HttpWindowsProxy.cs"
Link="ProductionCode\HttpWindowsProxy.cs" />
<Compile Include="..\..\..\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\FailedProxyCache.cs"
Link="ProductionCode\FailedProxyCache.cs" />
<Compile Include="..\..\..\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\IMultiWebProxy.cs"
Expand All @@ -104,7 +100,6 @@
<Compile Include="FakeRegistry.cs" />
<Compile Include="FakeSafeWinHttpHandle.cs" />
<Compile Include="FakeX509Certificates.cs" />
<Compile Include="HttpWindowsProxyTest.cs" />
<Compile Include="SafeWinHttpHandleTest.cs" />
<Compile Include="SendRequestHelper.cs" />
<Compile Include="TestServer.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public static class TestControl

public static int LastWin32Error { get; set; }

public static bool WinHttpAutomaticProxySupport { get; set; }
public static bool WinHttpDecompressionSupport { get; set; }

public static bool PACFileNotDetectedOnNetwork { get; set; }
Expand All @@ -32,7 +31,6 @@ public static void Reset()
WinHttpReceiveResponse = new ApiControl();
WinHttpWriteData = new ApiControl();

WinHttpAutomaticProxySupport = true;
WinHttpDecompressionSupport = true;

LastWin32Error = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,6 @@ await VerifyResponseContent(
[Fact]
public void SendAsync_AutomaticProxySupportAndUseWinInetSettings_ExpectedWinHttpSessionProxySettings()
{
TestControl.WinHttpAutomaticProxySupport = true;
var handler = new WinHttpHandler();

SendRequestHelper.Send(
Expand All @@ -797,120 +796,6 @@ public void SendAsync_AutomaticProxySupportAndUseWinInetSettings_ExpectedWinHttp
Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, APICallHistory.SessionProxySettings.AccessType);
}

[Fact]
public void SendAsync_NoAutomaticProxySupportAndUseWinInetSettingsWithAutoDetectSetting_ExpectedWinHttpProxySettings()
{
TestControl.WinHttpAutomaticProxySupport = false;
FakeRegistry.WinInetProxySettings.AutoDetect = true;
var handler = new WinHttpHandler();

SendRequestHelper.Send(
handler,
delegate
{
handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
});

Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType);
Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NAMED_PROXY, APICallHistory.RequestProxySettings.AccessType);
}

[Fact]
public void SendAsync_NoAutomaticProxySupportAndUseWinInetSettingsWithEmptySettings_ExpectedWinHttpProxySettings()
{
TestControl.WinHttpAutomaticProxySupport = false;
var handler = new WinHttpHandler();

SendRequestHelper.Send(
handler,
delegate
{
handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
});

Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType);
Assert.False(APICallHistory.RequestProxySettings.AccessType.HasValue);
}

[Fact]
public void SendAsync_NoAutomaticProxySupportAndUseWinInetSettingsWithManualSettingsOnly_ExpectedWinHttpProxySettings()
{
TestControl.WinHttpAutomaticProxySupport = false;
FakeRegistry.WinInetProxySettings.Proxy = FakeProxy;
var handler = new WinHttpHandler();

SendRequestHelper.Send(
handler,
delegate
{
handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
});

Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NAMED_PROXY, APICallHistory.SessionProxySettings.AccessType);
Assert.False(APICallHistory.RequestProxySettings.AccessType.HasValue);
}

[Fact]
public void SendAsync_NoAutomaticProxySupportAndUseWinInetSettingsWithMissingRegistrySettings_ExpectedWinHttpProxySettings()
{
TestControl.WinHttpAutomaticProxySupport = false;
FakeRegistry.WinInetProxySettings.RegistryKeyMissing = true;
var handler = new WinHttpHandler();

SendRequestHelper.Send(
handler,
delegate
{
handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
});

Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType);
Assert.False(APICallHistory.RequestProxySettings.AccessType.HasValue);
}

[Fact]
public void SendAsync_NoAutomaticProxySupportAndUseWinInetSettingsWithAutoDetectButPACFileNotDetectedOnNetwork_ExpectedWinHttpProxySettings()
{
TestControl.WinHttpAutomaticProxySupport = false;
TestControl.PACFileNotDetectedOnNetwork = true;
FakeRegistry.WinInetProxySettings.AutoDetect = true;
var handler = new WinHttpHandler();

SendRequestHelper.Send(
handler,
delegate
{
handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
});

Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType);
Assert.Null(APICallHistory.RequestProxySettings.AccessType);
}

[Fact]
public void SendAsync_NoAutomaticProxySupportAndUseWinInetSettingsWithAutoDetectSettingAndManualSettingButPACFileNotFoundOnNetwork_ExpectedWinHttpProxySettings()
{
const string manualProxy = FakeProxy;
TestControl.WinHttpAutomaticProxySupport = false;
FakeRegistry.WinInetProxySettings.AutoDetect = true;
FakeRegistry.WinInetProxySettings.Proxy = manualProxy;
TestControl.PACFileNotDetectedOnNetwork = true;
var handler = new WinHttpHandler();

SendRequestHelper.Send(
handler,
delegate
{
handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
});

// Both AutoDetect and manual proxy are specified. If AutoDetect fails to find
// the PAC file on the network, then we should fall back to manual setting.
Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType);
Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NAMED_PROXY, APICallHistory.RequestProxySettings.AccessType);
Assert.Equal(manualProxy, APICallHistory.RequestProxySettings.Proxy);
}

[Fact]
public void SendAsync_UseNoProxy_ExpectedWinHttpProxySettings()
{
Expand Down Expand Up @@ -961,7 +846,6 @@ public void SendAsync_UseCustomProxyWithBypass_ExpectedWinHttpProxySettings()
[Fact]
public void SendAsync_AutomaticProxySupportAndUseDefaultWebProxy_ExpectedWinHttpSessionProxySettings()
{
TestControl.WinHttpAutomaticProxySupport = true;
var handler = new WinHttpHandler();

SendRequestHelper.Send(
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/System.Net.Http/src/System.Net.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
<Compile Include="System\Net\Http\SocketsHttpHandler\HttpEnvironmentProxy.Windows.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\HttpNoProxy.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\HttpWindowsProxy.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\WinInetProxyHelper.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\CurrentUserIdentityProvider.Windows.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.BOOL.cs"
Link="Common\Interop\Windows\Interop.BOOL.cs" />
Expand All @@ -395,8 +396,6 @@
Link="Common\System\Net\UriScheme.cs" />
<Compile Include="$(CommonPath)\System\Net\Http\HttpHandlerDefaults.cs"
Link="Common\System\Net\Http\HttpHandlerDefaults.cs" />
<Compile Include="$(CommonPath)\System\Net\Http\WinInetProxyHelper.cs"
Link="Common\System\Net\Http\WinInetProxyHelper.cs" />
<Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.cs"
Link="Common\System\Net\Security\CertificateHelper.cs" />
<Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.Windows.cs"
Expand Down
Loading