* Removed WinHttpHandler from System.Net.Http.
* Disabled tests for WinHttpHandler.
* Removed UseSocketsHttpHandler settings
* Removed UseSocketsHttpHandler from tests (all tests use SocketsHttpHandler)
* Removed IsWinHttpHandler from tests.
* Updated WinHttpHandler project file.
* Fixed Linux build/tests.
* Fixed Win build of WinHttpHandler.
* Removed todos.
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsNetStandard)' == 'true' and '$(TargetsWindows)' != 'true'">SR.PlatformNotSupported_WinHttpHandler</GeneratePlatformNotSupportedAssemblyMessage>
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
<Configurations>net461-Windows_NT-Debug;net461-Windows_NT-Release;netfx-Windows_NT-Debug;netfx-Windows_NT-Release;netstandard2.0-Debug;netstandard2.0-Release;netstandard2.0-Windows_NT-Debug;netstandard2.0-Windows_NT-Release</Configurations>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
- <Import Project="System.Net.Http.WinHttpHandler.msbuild" Condition="'$(TargetsWindows)' == 'true'" />
- <ItemGroup Condition="'$(TargetFramework)' == 'net46' or '$(TargetFramework)' == 'net461'">
- <!-- Need to compile it here since the NET46 target here is building against System.Runtime whereas the
- the list of other files in System.Net.Http.WinHttpHandler.msbuild is also used by System.Net.Http
- library and the NET46 target there uses framework assembly references instead. -->
- <CompileItem Include="$(CommonPath)System\Net\HttpStatusDescription.cs" />
+ <ItemGroup Condition="'$(TargetsWindows)' == 'true'" >
+ <Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
+ <Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.CertEnumCertificatesInStore.cs">
+ <Link>Common\Interop\Windows\Crypt32\Interop.CertEnumCertificatesInStore.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.certificates_types.cs">
+ <Link>Common\Interop\Windows\Crypt32\Interop.certificates_types.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.certificates.cs">
+ <Link>Common\Interop\Windows\Crypt32\Interop.certificates.cs</Link>
+ </Compile>
+ <Compile Include="$(CoreLibSharedDir)Interop\Windows\Kernel32\Interop.FormatMessage.cs">
+ <Link>System\Interop\Windows\Kernel32\Interop.FormatMessage.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.GetModuleHandle.cs">
+ <Link>Common\Interop\Windows\Kernel32\Interop.GetModuleHandle.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Interop.HRESULT_FROM_WIN32.cs">
+ <Link>Common\Interop\Windows\Interop.HRESULT_FROM_WIN32.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\SChannel\UnmanagedCertificateContext.IntPtr.cs">
+ <Link>Common\Interop\Windows\SChannel\UnmanagedCertificateContext.IntPtr.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\WinHttp\Interop.SafeWinHttpHandle.cs">
+ <Link>Common\Interop\Windows\WinHttp\Interop.SafeWinHttpHandle.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\WinHttp\Interop.winhttp_types.cs">
+ <Link>Common\Interop\Windows\WinHttp\Interop.winhttp_types.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\WinHttp\Interop.winhttp.cs">
+ <Link>Common\Interop\Windows\WinHttp\Interop.winhttp.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\CharArrayHelpers.cs">
+ <Link>Common\System\CharArrayHelpers.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\StringExtensions.cs">
+ <Link>Common\System\StringExtensions.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\HttpKnownHeaderNames.cs">
+ <Link>Common\System\Net\HttpKnownHeaderNames.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\HttpKnownHeaderNames.TryGetHeaderName.cs">
+ <Link>Common\System\Net\HttpKnownHeaderNames.TryGetHeaderName.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)System\Net\HttpStatusDescription.cs">
+ <Link>Common\System\Net\Http\HttpStatusDescription.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\SecurityProtocol.cs">
+ <Link>Common\System\Net\SecurityProtocol.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\UriScheme.cs">
+ <Link>Common\System\Net\UriScheme.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Http\HttpHandlerDefaults.cs">
+ <Link>Common\System\Net\Http\HttpHandlerDefaults.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Http\NoWriteNoSeekStreamContent.cs">
+ <Link>Common\System\Net\Http\NoWriteNoSeekStreamContent.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Http\WinInetProxyHelper.cs">
+ <Link>Common\System\Net\Http\WinInetProxyHelper.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.cs">
+ <Link>Common\System\Net\Security\CertificateHelper.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.Windows.cs">
+ <Link>Common\System\Net\Security\CertificateHelper.Windows.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Runtime\ExceptionServices\ExceptionStackTrace.cs">
+ <Link>Common\System\Runtime\ExceptionServices\ExceptionStackTrace.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Threading\Tasks\RendezvousAwaitable.cs">
+ <Link>Common\System\Threading\Tasks\RendezvousAwaitable.cs</Link>
+ </Compile>
+ <Compile Include="$(CoreLibSharedDir)System\Threading\Tasks\TaskToApm.cs">
+ <Link>System\System\Threading\Tasks\TaskToApm.cs</Link>
+ </Compile>
</ItemGroup>
- <!-- For source files to be shown within the visual tree in Solution Explorer, the items must be
- included directly in the project file. We have the *.msbuild define the Compile items in a made
- up item called CompileItem and then just include it here. -->
<ItemGroup Condition=" '$(TargetsWindows)' == 'true' ">
- <Compile Include="@(CompileItem)" />
<Compile Include="System\Net\Http\NetEventSource.WinHttpHandler.cs" />
+ <Compile Include="System\Net\Http\WinHttpAuthHelper.cs" />
+ <Compile Include="System\Net\Http\WinHttpCertificateHelper.cs" />
+ <Compile Include="System\Net\Http\WinHttpChannelBinding.cs" />
+ <Compile Include="System\Net\Http\WinHttpCookieContainerAdapter.cs" />
+ <Compile Include="System\Net\Http\WinHttpException.cs" />
+ <Compile Include="System\Net\Http\WinHttpHandler.cs" />
+ <Compile Include="System\Net\Http\WinHttpRequestCallback.cs" />
+ <Compile Include="System\Net\Http\WinHttpRequestState.cs" />
+ <Compile Include="System\Net\Http\WinHttpRequestStream.cs" />
+ <Compile Include="System\Net\Http\WinHttpResponseHeaderReader.cs" />
+ <Compile Include="System\Net\Http\WinHttpResponseParser.cs" />
+ <Compile Include="System\Net\Http\WinHttpResponseStream.cs" />
+ <Compile Include="System\Net\Http\WinHttpTraceHelper.cs" />
+ <Compile Include="System\Net\Http\WinHttpTransportContext.cs" />
<Compile Include="$(CoreLibSharedDir)System\IO\StreamHelpers.CopyValidation.cs">
<Link>System\IO\StreamHelpers.CopyValidation.cs</Link>
</Compile>
+++ /dev/null
-<Project DefaultTargets="Build">
- <PropertyGroup>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- </PropertyGroup>
- <ItemGroup>
- <CompileItem Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs" />
- <CompileItem Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.CertEnumCertificatesInStore.cs" />
- <CompileItem Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.certificates_types.cs" />
- <CompileItem Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.certificates.cs" />
- <CompileItem Include="$(CoreLibSharedDir)Interop\Windows\Kernel32\Interop.FormatMessage.cs" />
- <CompileItem Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.GetModuleHandle.cs" />
- <CompileItem Include="$(CommonPath)\Interop\Windows\Interop.HRESULT_FROM_WIN32.cs" />
- <CompileItem Include="$(CommonPath)\Interop\Windows\SChannel\UnmanagedCertificateContext.IntPtr.cs" />
- <CompileItem Include="$(CommonPath)\Interop\Windows\WinHttp\Interop.SafeWinHttpHandle.cs" />
- <CompileItem Include="$(CommonPath)\Interop\Windows\WinHttp\Interop.winhttp_types.cs" />
- <CompileItem Include="$(CommonPath)\Interop\Windows\WinHttp\Interop.winhttp.cs" />
- <CompileItem Include="$(CommonPath)\System\CharArrayHelpers.cs" />
- <CompileItem Include="$(CommonPath)\System\StringExtensions.cs" />
- <CompileItem Include="$(CommonPath)\System\Net\HttpKnownHeaderNames.cs" />
- <CompileItem Include="$(CommonPath)\System\Net\HttpKnownHeaderNames.TryGetHeaderName.cs" />
- <CompileItem Include="$(CommonPath)\System\Net\SecurityProtocol.cs" />
- <CompileItem Include="$(CommonPath)\System\Net\UriScheme.cs" />
- <CompileItem Include="$(CommonPath)\System\Net\Http\HttpHandlerDefaults.cs" />
- <CompileItem Include="$(CommonPath)\System\Net\Http\NoWriteNoSeekStreamContent.cs" />
- <CompileItem Include="$(CommonPath)\System\Net\Security\CertificateHelper.cs" />
- <CompileItem Include="$(CommonPath)\System\Net\Security\CertificateHelper.Windows.cs" />
- <CompileItem Include="$(CommonPath)\System\Runtime\ExceptionServices\ExceptionStackTrace.cs" />
- <CompileItem Include="$(CommonPath)\System\Threading\Tasks\RendezvousAwaitable.cs" />
- <CompileItem Include="$(CoreLibSharedDir)System\Threading\Tasks\TaskToApm.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpAuthHelper.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpCertificateHelper.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpChannelBinding.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpCookieContainerAdapter.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpException.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpHandler.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpRequestCallback.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpRequestState.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpRequestStream.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpResponseHeaderReader.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpResponseParser.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpResponseStream.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpTraceHelper.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpTransportContext.cs" />
- <CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinInetProxyHelper.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetGroup)' != 'net46' AND '$(TargetGroup)' != 'net461'">
- <CompileItem Include="$(CommonPath)\System\Net\HttpStatusDescription.cs" />
- </ItemGroup>
-</Project>
<Compile Include="$(CommonPath)System\Net\Http\NoWriteNoSeekStreamContent.cs">
<Link>Common\System\Net\Http\NoWriteNoSeekStreamContent.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\System\Net\Http\WinInetProxyHelper.cs">
+ <Link>Common\System\Net\Http\WinInetProxyHelper.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)System\Net\Security\CertificateHelper.cs">
<Link>Common\System\Net\Security\CertificateHelper.cs</Link>
</Compile>
<Compile Include="..\..\src\System\Net\Http\WinHttpTransportContext.cs">
<Link>ProductionCode\WinHttpTransportContext.cs</Link>
</Compile>
- <Compile Include="..\..\src\System\Net\Http\WinInetProxyHelper.cs">
- <Link>ProductionCode\WinInetProxyHelper.cs</Link>
- </Compile>
<Compile Include="..\..\..\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\HttpWindowsProxy.cs">
<Link>ProductionCode\HttpWindowsProxy.cs</Link>
</Compile>
<Compile Include="System\Net\Http\Headers\KnownHeaders.cs" />
<Compile Include="System\Net\Http\HttpClient.cs" />
<Compile Include="System\Net\Http\HttpClientHandler.cs" />
+ <Compile Include="System\Net\Http\HttpClientHandler.Core.cs" />
+ <Compile Include="System\Net\Http\HttpClientHandler.netcoreapp.cs" />
<Compile Include="System\Net\Http\HttpCompletionOption.cs" />
<Compile Include="System\Net\Http\HttpContent.cs" />
<Compile Include="System\Net\Http\HttpMessageHandler.cs" />
<Link>Common\Microsoft\Win32\SafeHandles\SafeCreateHandle.OSX.cs</Link>
</Compile>
</ItemGroup>
+ <ItemGroup Condition=" '$(TargetsWindows)' == 'true' AND '$(TargetGroup)' != 'net46' AND '$(TargetGroup)' != 'net461' ">
+ <Compile Include="$(CommonPath)\System\Net\HttpStatusDescription.cs">
+ <Link>Common\System\Net\HttpStatusDescription.cs</Link>
+ </Compile>
+ </ItemGroup>
<ItemGroup Condition=" '$(TargetsWindows)' == 'true'">
<Compile Include="System\Net\Http\SocketsHttpHandler\SystemProxyInfo.Windows.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\HttpEnvironmentProxy.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\HttpNoProxy.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\HttpWindowsProxy.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\CurrentUserIdentityProvider.Windows.cs" />
+ <Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
+ <Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.CertEnumCertificatesInStore.cs">
+ <Link>Common\Interop\Windows\Crypt32\Interop.CertEnumCertificatesInStore.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.certificates_types.cs">
+ <Link>Common\Interop\Windows\Crypt32\Interop.certificates_types.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.certificates.cs">
+ <Link>Common\Interop\Windows\Crypt32\Interop.certificates.cs</Link>
+ </Compile>
+ <Compile Include="$(CoreLibSharedDir)Interop\Windows\Kernel32\Interop.FormatMessage.cs">
+ <Link>System\Interop\Windows\Kernel32\Interop.FormatMessage.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.GetModuleHandle.cs">
+ <Link>Common\Interop\Windows\Kernel32\Interop.GetModuleHandle.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Interop.HRESULT_FROM_WIN32.cs">
+ <Link>Common\Interop\Windows\Interop.HRESULT_FROM_WIN32.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\SChannel\UnmanagedCertificateContext.IntPtr.cs">
+ <Link>Common\Interop\Windows\SChannel\UnmanagedCertificateContext.IntPtr.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\WinHttp\Interop.SafeWinHttpHandle.cs">
+ <Link>Common\Interop\Windows\WinHttp\Interop.SafeWinHttpHandle.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\WinHttp\Interop.winhttp_types.cs">
+ <Link>Common\Interop\Windows\WinHttp\Interop.winhttp_types.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\WinHttp\Interop.winhttp.cs">
+ <Link>Common\Interop\Windows\WinHttp\Interop.winhttp.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\CharArrayHelpers.cs">
+ <Link>Common\System\CharArrayHelpers.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\StringExtensions.cs">
+ <Link>Common\System\StringExtensions.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\HttpKnownHeaderNames.cs">
+ <Link>Common\System\Net\HttpKnownHeaderNames.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\HttpKnownHeaderNames.TryGetHeaderName.cs">
+ <Link>Common\System\Net\HttpKnownHeaderNames.TryGetHeaderName.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\SecurityProtocol.cs">
+ <Link>Common\System\Net\SecurityProtocol.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\UriScheme.cs">
+ <Link>Common\System\Net\UriScheme.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Http\HttpHandlerDefaults.cs">
+ <Link>Common\System\Net\Http\HttpHandlerDefaults.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Http\NoWriteNoSeekStreamContent.cs">
+ <Link>Common\System\Net\Http\NoWriteNoSeekStreamContent.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Http\WinInetProxyHelper.cs">
+ <Link>Common\System\Net\Http\WinInetProxyHelper.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.cs">
+ <Link>Common\System\Net\Security\CertificateHelper.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.Windows.cs">
+ <Link>Common\System\Net\Security\CertificateHelper.Windows.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Runtime\ExceptionServices\ExceptionStackTrace.cs">
+ <Link>Common\System\Runtime\ExceptionServices\ExceptionStackTrace.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\System\Threading\Tasks\RendezvousAwaitable.cs">
+ <Link>Common\System\Threading\Tasks\RendezvousAwaitable.cs</Link>
+ </Compile>
+ <Compile Include="$(CoreLibSharedDir)System\Threading\Tasks\TaskToApm.cs">
+ <Link>System\System\Threading\Tasks\TaskToApm.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)Interop\Windows\SChannel\Interop.SecPkgContext_ApplicationProtocol.cs">
<Link>Common\Interop\Windows\SChannel\Interop.SecPkgContext_ApplicationProtocol.cs</Link>
</Compile>
<Link>Common\System\Net\Mail\WhitespaceReader.cs</Link>
</Compile>
</ItemGroup>
- <!-- WinHttpHandler implementation -->
- <ItemGroup Condition=" '$(TargetsWindows)' == 'true'">
- <Compile Include="System\Net\Http\HttpClientHandler.Core.cs" />
- <Compile Include="System\Net\Http\HttpClientHandler.netcoreapp.cs" />
- <Compile Include="System\Net\Http\HttpClientHandler.Windows.cs" />
- </ItemGroup>
- <!-- Compile the WinHttpHandler implementation into the System.Net.Http.dll binary. This is a
- temporary solution to remove the cycle dependency between HttpClient and WinHttpHandler.
- As part of that, we need to define HTTP_DLL in order to compile the 'protected' SendAsync()
- method in WinHttpHandler.cs as 'protected internal' to match the internal definition in
- HttpMessageHandler.cs. We also use the HTTP_DLL define to change public classes into
- internal ones to remove confusion if someone looks at the implementation dlls. They are
- public in the separate WinHttpHandler.dll binary. -->
- <Import Project="..\..\System.Net.Http.WinHttpHandler\src\System.Net.Http.WinHttpHandler.msbuild" Condition="'$(TargetsWindows)' == 'true'" />
- <!-- For source files to be shown within the visual tree in Solution Explorer, the items must be
- included directly in the project file. We have the *.msbuild define the Compile items in a made
- up item called CompileItem and then just include it here. -->
- <ItemGroup Condition="'$(TargetsWindows)' == 'true'">
- <Compile Include="@(CompileItem)" />
- </ItemGroup>
- <!-- CurlHandler implementation -->
- <PropertyGroup Condition=" '$(TargetsUnix)' == 'true' ">
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- </PropertyGroup>
<ItemGroup Condition=" '$(TargetsUnix)' == 'true' ">
- <Compile Include="System\Net\Http\HttpClientHandler.Core.cs" />
- <Compile Include="System\Net\Http\HttpClientHandler.netcoreapp.cs" />
- <Compile Include="System\Net\Http\HttpClientHandler.Unix.cs" />
<Compile Include="$(CommonPath)System\StrongToWeakReference.cs">
<Link>Common\Interop\Unix\StrongToWeakReference.cs</Link>
</Compile>
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using System.Net.Security;
-using System.Security.Authentication;
-using System.Security.Cryptography.X509Certificates;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.Net.Http
-{
- public partial class HttpClientHandler : HttpMessageHandler
- {
- private readonly SocketsHttpHandler _socketsHttpHandler;
- private readonly DiagnosticsHandler _diagnosticsHandler;
- private ClientCertificateOption _clientCertificateOptions;
-
- public HttpClientHandler()
- {
- _socketsHttpHandler = new SocketsHttpHandler();
- _diagnosticsHandler = new DiagnosticsHandler(_socketsHttpHandler);
- ClientCertificateOptions = ClientCertificateOption.Manual;
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- _socketsHttpHandler.Dispose();
- }
- base.Dispose(disposing);
- }
-
- public virtual bool SupportsAutomaticDecompression => true;
-
- public virtual bool SupportsProxy => true;
-
- public virtual bool SupportsRedirectConfiguration => true;
-
- public bool UseCookies
- {
- get => _socketsHttpHandler.UseCookies;
- set => _socketsHttpHandler.UseCookies = value;
- }
-
- public CookieContainer CookieContainer
- {
- get => _socketsHttpHandler.CookieContainer;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- _socketsHttpHandler.CookieContainer = value;
- }
- }
-
- public ClientCertificateOption ClientCertificateOptions
- {
- get => _clientCertificateOptions;
- set
- {
- switch (value)
- {
- case ClientCertificateOption.Manual:
- ThrowForModifiedManagedSslOptionsIfStarted();
- _clientCertificateOptions = value;
- _socketsHttpHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate(ClientCertificates);
- break;
-
- case ClientCertificateOption.Automatic:
- ThrowForModifiedManagedSslOptionsIfStarted();
- _clientCertificateOptions = value;
- _socketsHttpHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate();
- break;
-
- default:
- throw new ArgumentOutOfRangeException(nameof(value));
- }
- }
- }
-
- public X509CertificateCollection ClientCertificates
- {
- get
- {
- if (ClientCertificateOptions != ClientCertificateOption.Manual)
- {
- throw new InvalidOperationException(SR.Format(SR.net_http_invalid_enable_first, nameof(ClientCertificateOptions), nameof(ClientCertificateOption.Manual)));
- }
-
- return _socketsHttpHandler.SslOptions.ClientCertificates ??
- (_socketsHttpHandler.SslOptions.ClientCertificates = new X509CertificateCollection());
- }
- }
-
- public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> ServerCertificateCustomValidationCallback
- {
- get => (_socketsHttpHandler.SslOptions.RemoteCertificateValidationCallback?.Target as ConnectHelper.CertificateCallbackMapper)?.FromHttpClientHandler;
- set
- {
- ThrowForModifiedManagedSslOptionsIfStarted();
- _socketsHttpHandler.SslOptions.RemoteCertificateValidationCallback = value != null ?
- new ConnectHelper.CertificateCallbackMapper(value).ForSocketsHttpHandler :
- null;
- }
- }
-
- public bool CheckCertificateRevocationList
- {
- get => _socketsHttpHandler.SslOptions.CertificateRevocationCheckMode == X509RevocationMode.Online;
- set
- {
- ThrowForModifiedManagedSslOptionsIfStarted();
- _socketsHttpHandler.SslOptions.CertificateRevocationCheckMode = value ? X509RevocationMode.Online : X509RevocationMode.NoCheck;
- }
- }
-
- public SslProtocols SslProtocols
- {
- get => _socketsHttpHandler.SslOptions.EnabledSslProtocols;
- set
- {
- ThrowForModifiedManagedSslOptionsIfStarted();
- _socketsHttpHandler.SslOptions.EnabledSslProtocols = value;
- }
- }
-
- public DecompressionMethods AutomaticDecompression
- {
- get => _socketsHttpHandler.AutomaticDecompression;
- set => _socketsHttpHandler.AutomaticDecompression = value;
- }
-
- public bool UseProxy
- {
- get => _socketsHttpHandler.UseProxy;
- set => _socketsHttpHandler.UseProxy = value;
- }
-
- public IWebProxy Proxy
- {
- get => _socketsHttpHandler.Proxy;
- set => _socketsHttpHandler.Proxy = value;
- }
-
- public ICredentials DefaultProxyCredentials
- {
- get => _socketsHttpHandler.DefaultProxyCredentials;
- set => _socketsHttpHandler.DefaultProxyCredentials = value;
- }
-
- public bool PreAuthenticate
- {
- get => _socketsHttpHandler.PreAuthenticate;
- set => _socketsHttpHandler.PreAuthenticate = value;
- }
-
- public bool UseDefaultCredentials
- {
- // Compare .Credentials as socketsHttpHandler does not have separate prop.
- get => _socketsHttpHandler.Credentials == CredentialCache.DefaultCredentials;
- set
- {
- if (value)
- {
- _socketsHttpHandler.Credentials = CredentialCache.DefaultCredentials;
- }
- else
- {
- if (_socketsHttpHandler.Credentials == CredentialCache.DefaultCredentials)
- {
- // Only clear out the Credentials property if it was a DefaultCredentials.
- _socketsHttpHandler.Credentials = null;
- }
- }
- }
- }
-
- public ICredentials Credentials
- {
- get => _socketsHttpHandler.Credentials;
- set => _socketsHttpHandler.Credentials = value;
- }
-
- public bool AllowAutoRedirect
- {
- get => _socketsHttpHandler.AllowAutoRedirect;
- set => _socketsHttpHandler.AllowAutoRedirect = value;
- }
-
- public int MaxAutomaticRedirections
- {
- get => _socketsHttpHandler.MaxAutomaticRedirections;
- set => _socketsHttpHandler.MaxAutomaticRedirections = value;
- }
-
- public int MaxConnectionsPerServer
- {
- get => _socketsHttpHandler.MaxConnectionsPerServer;
- set => _socketsHttpHandler.MaxConnectionsPerServer = value;
- }
-
- public int MaxResponseHeadersLength
- {
- get => _socketsHttpHandler.MaxResponseHeadersLength;
- set => _socketsHttpHandler.MaxResponseHeadersLength = value;
- }
-
- public IDictionary<string, object> Properties => _socketsHttpHandler.Properties;
-
- protected internal override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) =>
- DiagnosticsHandler.IsEnabled() ? _diagnosticsHandler.SendAsync(request, cancellationToken) :
- _socketsHttpHandler.SendAsync(request, cancellationToken);
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using System.Net.Security;
-using System.Security.Authentication;
-using System.Security.Cryptography.X509Certificates;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.Net.Http
-{
- // This implementation uses the System.Net.Http.WinHttpHandler class on Windows. Other platforms will need to use
- // their own platform specific implementation.
- public partial class HttpClientHandler : HttpMessageHandler
- {
- private readonly WinHttpHandler _winHttpHandler;
- private readonly SocketsHttpHandler _socketsHttpHandler;
- private readonly DiagnosticsHandler _diagnosticsHandler;
- private bool _useProxy;
- private ClientCertificateOption _clientCertificateOptions;
-
- public HttpClientHandler() : this(UseSocketsHttpHandler) { }
-
- private HttpClientHandler(bool useSocketsHttpHandler) // used by parameterless ctor and as hook for testing
- {
- if (useSocketsHttpHandler)
- {
- _socketsHttpHandler = new SocketsHttpHandler();
- _diagnosticsHandler = new DiagnosticsHandler(_socketsHttpHandler);
- ClientCertificateOptions = ClientCertificateOption.Manual;
-
- }
- else
- {
- _winHttpHandler = new WinHttpHandler();
- _diagnosticsHandler = new DiagnosticsHandler(_winHttpHandler);
-
- // Adjust defaults to match current .NET Desktop HttpClientHandler (based on HWR stack).
- AllowAutoRedirect = true;
- AutomaticDecompression = HttpHandlerDefaults.DefaultAutomaticDecompression;
- UseProxy = true;
- UseCookies = true;
- CookieContainer = new CookieContainer();
- _winHttpHandler.DefaultProxyCredentials = null;
- _winHttpHandler.ServerCredentials = null;
-
- // The existing .NET Desktop HttpClientHandler based on the HWR stack uses only WinINet registry
- // settings for the proxy. This also includes supporting the "Automatic Detect a proxy" using
- // WPAD protocol and PAC file. So, for app-compat, we will do the same for the default proxy setting.
- _winHttpHandler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
- _winHttpHandler.Proxy = null;
-
- // Since the granular WinHttpHandler timeout properties are not exposed via the HttpClientHandler API,
- // we need to set them to infinite and allow the HttpClient.Timeout property to have precedence.
- _winHttpHandler.ReceiveHeadersTimeout = Timeout.InfiniteTimeSpan;
- _winHttpHandler.ReceiveDataTimeout = Timeout.InfiniteTimeSpan;
- _winHttpHandler.SendTimeout = Timeout.InfiniteTimeSpan;
- }
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing && !_disposed)
- {
- _disposed = true;
- ((HttpMessageHandler)_winHttpHandler ?? _socketsHttpHandler).Dispose();
- }
-
- base.Dispose(disposing);
- }
-
- public virtual bool SupportsAutomaticDecompression => true;
- public virtual bool SupportsProxy => true;
- public virtual bool SupportsRedirectConfiguration => true;
-
- public bool UseCookies
- {
- get => _winHttpHandler != null ? _winHttpHandler.CookieUsePolicy == CookieUsePolicy.UseSpecifiedCookieContainer : _socketsHttpHandler.UseCookies;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.CookieUsePolicy = value ? CookieUsePolicy.UseSpecifiedCookieContainer : CookieUsePolicy.IgnoreCookies;
- }
- else
- {
- _socketsHttpHandler.UseCookies = value;
- }
- }
- }
-
- public CookieContainer CookieContainer
- {
- get => _winHttpHandler != null ? _winHttpHandler.CookieContainer : _socketsHttpHandler.CookieContainer;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- if (_winHttpHandler != null)
- {
- _winHttpHandler.CookieContainer = value;
- }
- else
- {
- _socketsHttpHandler.CookieContainer = value;
- }
- }
- }
-
- public DecompressionMethods AutomaticDecompression
- {
- get => _winHttpHandler != null ? _winHttpHandler.AutomaticDecompression : _socketsHttpHandler.AutomaticDecompression;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.AutomaticDecompression = value;
- }
- else
- {
- _socketsHttpHandler.AutomaticDecompression = value;
- }
- }
- }
-
- public bool UseProxy
- {
- get => _winHttpHandler != null ? _useProxy : _socketsHttpHandler.UseProxy;
- set
- {
- if (_winHttpHandler != null)
- {
- _useProxy = value;
- }
- else
- {
- _socketsHttpHandler.UseProxy = value;
- }
- }
- }
-
- public IWebProxy Proxy
- {
- get => _winHttpHandler != null ? _winHttpHandler.Proxy : _socketsHttpHandler.Proxy;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.Proxy = value;
- }
- else
- {
- _socketsHttpHandler.Proxy = value;
- }
- }
- }
-
- public ICredentials DefaultProxyCredentials
- {
- get => _winHttpHandler != null ? _winHttpHandler.DefaultProxyCredentials : _socketsHttpHandler.DefaultProxyCredentials;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.DefaultProxyCredentials = value;
- }
- else
- {
- _socketsHttpHandler.DefaultProxyCredentials = value;
- }
- }
- }
-
- public bool PreAuthenticate
- {
- get => _winHttpHandler != null ? _winHttpHandler.PreAuthenticate : _socketsHttpHandler.PreAuthenticate;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.PreAuthenticate = value;
- }
- else
- {
- _socketsHttpHandler.PreAuthenticate = value;
- }
- }
- }
-
- public bool UseDefaultCredentials
- {
- // WinHttpHandler doesn't have a separate UseDefaultCredentials property. There
- // is just a ServerCredentials property. So, we need to map the behavior.
- // Do the same for SocketsHttpHandler.Credentials.
- //
- // This property only affect .ServerCredentials and not .DefaultProxyCredentials.
-
- get => _winHttpHandler != null ? _winHttpHandler.ServerCredentials == CredentialCache.DefaultCredentials :
- _socketsHttpHandler.Credentials == CredentialCache.DefaultCredentials;
- set
- {
- if (_winHttpHandler != null)
- {
- if (value)
- {
- _winHttpHandler.ServerCredentials = CredentialCache.DefaultCredentials;
- }
- else
- {
- if (_winHttpHandler.ServerCredentials == CredentialCache.DefaultCredentials)
- {
- // Only clear out the ServerCredentials property if it was a DefaultCredentials.
- _winHttpHandler.ServerCredentials = null;
- }
- }
- }
- else
- {
- if (value)
- {
- _socketsHttpHandler.Credentials = CredentialCache.DefaultCredentials;
- }
- else
- {
- if (_socketsHttpHandler.Credentials == CredentialCache.DefaultCredentials)
- {
- // Only clear out the Credentials property if it was a DefaultCredentials.
- _socketsHttpHandler.Credentials = null;
- }
- }
- }
- }
- }
-
- public ICredentials Credentials
- {
- get => _winHttpHandler != null ? _winHttpHandler.ServerCredentials : _socketsHttpHandler.Credentials;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.ServerCredentials = value;
- }
- else
- {
- _socketsHttpHandler.Credentials = value;
- }
- }
- }
-
- public bool AllowAutoRedirect
- {
- get => _winHttpHandler != null ? _winHttpHandler.AutomaticRedirection : _socketsHttpHandler.AllowAutoRedirect;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.AutomaticRedirection = value;
- }
- else
- {
- _socketsHttpHandler.AllowAutoRedirect = value;
- }
- }
- }
-
- public int MaxAutomaticRedirections
- {
- get => _winHttpHandler != null ? _winHttpHandler.MaxAutomaticRedirections : _socketsHttpHandler.MaxAutomaticRedirections;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.MaxAutomaticRedirections = value;
- }
- else
- {
- _socketsHttpHandler.MaxAutomaticRedirections = value;
- }
- }
- }
-
- public int MaxConnectionsPerServer
- {
- get => _winHttpHandler != null ? _winHttpHandler.MaxConnectionsPerServer : _socketsHttpHandler.MaxConnectionsPerServer;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.MaxConnectionsPerServer = value;
- }
- else
- {
- _socketsHttpHandler.MaxConnectionsPerServer = value;
- }
- }
- }
-
- public int MaxResponseHeadersLength
- {
- get => _winHttpHandler != null ? _winHttpHandler.MaxResponseHeadersLength : _socketsHttpHandler.MaxResponseHeadersLength;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.MaxResponseHeadersLength = value;
- }
- else
- {
- _socketsHttpHandler.MaxResponseHeadersLength = value;
- }
- }
- }
-
- public ClientCertificateOption ClientCertificateOptions
- {
- get
- {
- if (_winHttpHandler != null)
- {
- return _winHttpHandler.ClientCertificateOption;
- }
- else
- {
- return _clientCertificateOptions;
- }
- }
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.ClientCertificateOption = value;
- }
- else
- {
- switch (value)
- {
- case ClientCertificateOption.Manual:
- ThrowForModifiedManagedSslOptionsIfStarted();
- _clientCertificateOptions = value;
- _socketsHttpHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate(ClientCertificates);
- break;
-
- case ClientCertificateOption.Automatic:
- ThrowForModifiedManagedSslOptionsIfStarted();
- _clientCertificateOptions = value;
- _socketsHttpHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate();
- break;
-
- default:
- throw new ArgumentOutOfRangeException(nameof(value));
- }
- }
- }
- }
-
- public X509CertificateCollection ClientCertificates
- {
- get
- {
- if (_winHttpHandler != null)
- {
- return _winHttpHandler.ClientCertificates;
- }
- else
- {
- if (ClientCertificateOptions != ClientCertificateOption.Manual)
- {
- throw new InvalidOperationException(SR.Format(SR.net_http_invalid_enable_first, nameof(ClientCertificateOptions), nameof(ClientCertificateOption.Manual)));
- }
-
- return _socketsHttpHandler.SslOptions.ClientCertificates ??
- (_socketsHttpHandler.SslOptions.ClientCertificates = new X509CertificateCollection());
- }
- }
- }
-
- public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> ServerCertificateCustomValidationCallback
- {
- get
- {
- return _winHttpHandler != null ?
- _winHttpHandler.ServerCertificateValidationCallback :
- (_socketsHttpHandler.SslOptions.RemoteCertificateValidationCallback?.Target as ConnectHelper.CertificateCallbackMapper)?.FromHttpClientHandler;
- }
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.ServerCertificateValidationCallback = value;
- }
- else
- {
- ThrowForModifiedManagedSslOptionsIfStarted();
- _socketsHttpHandler.SslOptions.RemoteCertificateValidationCallback = value != null ?
- new ConnectHelper.CertificateCallbackMapper(value).ForSocketsHttpHandler :
- null;
- }
- }
- }
-
- public bool CheckCertificateRevocationList
- {
- get => _winHttpHandler != null ? _winHttpHandler.CheckCertificateRevocationList : _socketsHttpHandler.SslOptions.CertificateRevocationCheckMode == X509RevocationMode.Online;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.CheckCertificateRevocationList = value;
- }
- else
- {
- ThrowForModifiedManagedSslOptionsIfStarted();
- _socketsHttpHandler.SslOptions.CertificateRevocationCheckMode = value ? X509RevocationMode.Online : X509RevocationMode.NoCheck;
- }
- }
- }
-
- public SslProtocols SslProtocols
- {
- get => _winHttpHandler != null ? _winHttpHandler.SslProtocols : _socketsHttpHandler.SslOptions.EnabledSslProtocols;
- set
- {
- if (_winHttpHandler != null)
- {
- _winHttpHandler.SslProtocols = value;
- }
- else
- {
- ThrowForModifiedManagedSslOptionsIfStarted();
- _socketsHttpHandler.SslOptions.EnabledSslProtocols = value;
- }
- }
- }
-
- public IDictionary<string, object> Properties => _winHttpHandler != null ?
- _winHttpHandler.Properties :
- _socketsHttpHandler.Properties;
-
- protected internal override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
- CancellationToken cancellationToken)
- {
- if (_winHttpHandler != null)
- {
- // Get current value of WindowsProxyUsePolicy. Only call its WinHttpHandler
- // property setter if the value needs to change.
- var oldProxyUsePolicy = _winHttpHandler.WindowsProxyUsePolicy;
-
- if (_useProxy)
- {
- if (_winHttpHandler.Proxy == null)
- {
- if (oldProxyUsePolicy != WindowsProxyUsePolicy.UseWinInetProxy)
- {
- _winHttpHandler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
- }
- }
- else
- {
- if (oldProxyUsePolicy != WindowsProxyUsePolicy.UseCustomProxy)
- {
- _winHttpHandler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseCustomProxy;
- }
- }
- }
- else
- {
- if (oldProxyUsePolicy != WindowsProxyUsePolicy.DoNotUseProxy)
- {
- _winHttpHandler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.DoNotUseProxy;
- }
- }
-
- return DiagnosticsHandler.IsEnabled() ?
- _diagnosticsHandler.SendAsync(request, cancellationToken) :
- _winHttpHandler.SendAsync(request, cancellationToken);
- }
- else
- {
- return DiagnosticsHandler.IsEnabled() ?
- _diagnosticsHandler.SendAsync(request, cancellationToken) :
- _socketsHttpHandler.SendAsync(request, cancellationToken);
- }
- }
- }
-}
using System.Diagnostics;
using System.Net.Security;
+using System.Collections.Generic;
+using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
+using System.Threading;
+using System.Threading.Tasks;
namespace System.Net.Http
{
public partial class HttpClientHandler : HttpMessageHandler
{
- // This partial implementation contains members common to all HttpClientHandler implementations.
- private const string SocketsHttpHandlerEnvironmentVariableSettingName = "DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER";
- private const string SocketsHttpHandlerAppCtxSettingName = "System.Net.Http.UseSocketsHttpHandler";
+ private readonly SocketsHttpHandler _socketsHttpHandler;
+ private readonly DiagnosticsHandler _diagnosticsHandler;
+ private ClientCertificateOption _clientCertificateOptions;
- private static bool UseSocketsHttpHandler
+ public HttpClientHandler()
{
- get
+ _socketsHttpHandler = new SocketsHttpHandler();
+ _diagnosticsHandler = new DiagnosticsHandler(_socketsHttpHandler);
+ ClientCertificateOptions = ClientCertificateOption.Manual;
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && !_disposed)
+ {
+ _disposed = true;
+ _socketsHttpHandler.Dispose();
+ }
+
+ base.Dispose(disposing);
+ }
+
+ public virtual bool SupportsAutomaticDecompression => true;
+ public virtual bool SupportsProxy => true;
+ public virtual bool SupportsRedirectConfiguration => true;
+
+ public bool UseCookies
+ {
+ get => _socketsHttpHandler.UseCookies;
+ set => _socketsHttpHandler.UseCookies = value;
+ }
+
+ public CookieContainer CookieContainer
+ {
+ get => _socketsHttpHandler.CookieContainer;
+ set
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException(nameof(value));
+ }
+
+ _socketsHttpHandler.CookieContainer = value;
+ }
+ }
+
+ public DecompressionMethods AutomaticDecompression
+ {
+ get => _socketsHttpHandler.AutomaticDecompression;
+ set => _socketsHttpHandler.AutomaticDecompression = value;
+ }
+
+ public bool UseProxy
+ {
+ get => _socketsHttpHandler.UseProxy;
+ set => _socketsHttpHandler.UseProxy = value;
+ }
+
+ public IWebProxy Proxy
+ {
+ get => _socketsHttpHandler.Proxy;
+ set => _socketsHttpHandler.Proxy = value;
+ }
+
+ public ICredentials DefaultProxyCredentials
+ {
+ get => _socketsHttpHandler.DefaultProxyCredentials;
+ set => _socketsHttpHandler.DefaultProxyCredentials = value;
+ }
+
+ public bool PreAuthenticate
+ {
+ get => _socketsHttpHandler.PreAuthenticate;
+ set => _socketsHttpHandler.PreAuthenticate = value;
+ }
+
+ public bool UseDefaultCredentials
+ {
+ // SocketsHttpHandler doesn't have a separate UseDefaultCredentials property. There
+ // is just a Credentials property. So, we need to map the behavior.
+ get => _socketsHttpHandler.Credentials == CredentialCache.DefaultCredentials;
+ set
+ {
+ if (value)
+ {
+ _socketsHttpHandler.Credentials = CredentialCache.DefaultCredentials;
+ }
+ else
+ {
+ if (_socketsHttpHandler.Credentials == CredentialCache.DefaultCredentials)
+ {
+ // Only clear out the Credentials property if it was a DefaultCredentials.
+ _socketsHttpHandler.Credentials = null;
+ }
+ }
+ }
+ }
+
+ public ICredentials Credentials
+ {
+ get => _socketsHttpHandler.Credentials;
+ set => _socketsHttpHandler.Credentials = value;
+ }
+
+ public bool AllowAutoRedirect
+ {
+ get => _socketsHttpHandler.AllowAutoRedirect;
+ set => _socketsHttpHandler.AllowAutoRedirect = value;
+ }
+
+ public int MaxAutomaticRedirections
+ {
+ get => _socketsHttpHandler.MaxAutomaticRedirections;
+ set => _socketsHttpHandler.MaxAutomaticRedirections = value;
+ }
+
+ public int MaxConnectionsPerServer
+ {
+ get => _socketsHttpHandler.MaxConnectionsPerServer;
+ set => _socketsHttpHandler.MaxConnectionsPerServer = value;
+ }
+
+ public int MaxResponseHeadersLength
+ {
+ get => _socketsHttpHandler.MaxResponseHeadersLength;
+ set => _socketsHttpHandler.MaxResponseHeadersLength = value;
+ }
+
+ public ClientCertificateOption ClientCertificateOptions
+ {
+ get => _clientCertificateOptions;
+ set
{
- // First check for the AppContext switch, giving it priority over the environment variable.
- if (AppContext.TryGetSwitch(SocketsHttpHandlerAppCtxSettingName, out bool useSocketsHttpHandler))
+ switch (value)
{
- return useSocketsHttpHandler;
+ case ClientCertificateOption.Manual:
+ ThrowForModifiedManagedSslOptionsIfStarted();
+ _clientCertificateOptions = value;
+ _socketsHttpHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate(ClientCertificates);
+ break;
+
+ case ClientCertificateOption.Automatic:
+ ThrowForModifiedManagedSslOptionsIfStarted();
+ _clientCertificateOptions = value;
+ _socketsHttpHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate();
+ break;
+
+ default:
+ throw new ArgumentOutOfRangeException(nameof(value));
}
+ }
+ }
- // AppContext switch wasn't used. Check the environment variable to determine which handler should be used.
- string envVar = Environment.GetEnvironmentVariable(SocketsHttpHandlerEnvironmentVariableSettingName);
- if (envVar != null && (envVar.Equals("false", StringComparison.OrdinalIgnoreCase) || envVar.Equals("0")))
+ public X509CertificateCollection ClientCertificates
+ {
+ get
+ {
+ if (ClientCertificateOptions != ClientCertificateOption.Manual)
{
- // Use WinHttpHandler on Windows.
- return false;
+ throw new InvalidOperationException(SR.Format(SR.net_http_invalid_enable_first, nameof(ClientCertificateOptions), nameof(ClientCertificateOption.Manual)));
}
- // Default to using SocketsHttpHandler.
- return true;
+ return _socketsHttpHandler.SslOptions.ClientCertificates ??
+ (_socketsHttpHandler.SslOptions.ClientCertificates = new X509CertificateCollection());
}
}
+ public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> ServerCertificateCustomValidationCallback
+ {
+ get => (_socketsHttpHandler.SslOptions.RemoteCertificateValidationCallback?.Target as ConnectHelper.CertificateCallbackMapper)?.FromHttpClientHandler;
+ set
+ {
+ ThrowForModifiedManagedSslOptionsIfStarted();
+ _socketsHttpHandler.SslOptions.RemoteCertificateValidationCallback = value != null ?
+ new ConnectHelper.CertificateCallbackMapper(value).ForSocketsHttpHandler :
+ null;
+ }
+ }
+
+ public bool CheckCertificateRevocationList
+ {
+ get => _socketsHttpHandler.SslOptions.CertificateRevocationCheckMode == X509RevocationMode.Online;
+ set
+ {
+ ThrowForModifiedManagedSslOptionsIfStarted();
+ _socketsHttpHandler.SslOptions.CertificateRevocationCheckMode = value ? X509RevocationMode.Online : X509RevocationMode.NoCheck;
+ }
+ }
+
+ public SslProtocols SslProtocols
+ {
+ get => _socketsHttpHandler.SslOptions.EnabledSslProtocols;
+ set
+ {
+ ThrowForModifiedManagedSslOptionsIfStarted();
+ _socketsHttpHandler.SslOptions.EnabledSslProtocols = value;
+ }
+ }
+
+ public IDictionary<string, object> Properties => _socketsHttpHandler.Properties;
+
+ protected internal override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
+ CancellationToken cancellationToken)
+ {
+ return DiagnosticsHandler.IsEnabled() ?
+ _diagnosticsHandler.SendAsync(request, cancellationToken) :
+ _socketsHttpHandler.SendAsync(request, cancellationToken);
+ }
public static Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> DangerousAcceptAnyServerCertificateValidator { get; } = delegate { return true; };
}
}
[Fact]
public void SendAsync_ExpectedDiagnosticSourceLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool requestLogged = false;
Guid requestGuid = Guid.Empty;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable(s => !s.Contains("HttpRequestOut"));
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
client.GetAsync(Configuration.Http.RemoteEchoServer).Result.Dispose();
}
Assert.False(activityLogged, "HttpOutReq was logged while HttpOutReq logging was disabled");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
/// <remarks>
[Fact]
public void SendAsync_ExpectedDiagnosticSourceNoLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool requestLogged = false;
bool responseLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
LoopbackServer.CreateServerAsync(async (server, url) =>
{
"Response was logged while logging disabled.");
Assert.False(activityStopLogged, "HttpRequestOut.Stop was logged while logging disabled.");
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[ActiveIssue(23771, TestPlatforms.AnyUnix)]
[InlineData(true)]
public void SendAsync_HttpTracingEnabled_Succeeds(bool useSsl)
{
- RemoteExecutor.Invoke(async (useSocketsHttpHandlerString, useHttp2String, useSslString) =>
+ RemoteExecutor.Invoke(async (useHttp2String, useSslString) =>
{
using (var listener = new TestEventListener("Microsoft-System-Net-Http", EventLevel.Verbose))
{
await listener.RunWithCallbackAsync(events.Enqueue, async () =>
{
// Exercise various code paths to get coverage of tracing
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
// Do a get to a loopback server
await LoopbackServer.CreateServerAsync(async (server, url) =>
ev => ev.EventId == 0); // make sure there are no event source error messages
Assert.InRange(events.Count, 1, int.MaxValue);
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString(), useSsl.ToString()).Dispose();
+ }, UseHttp2.ToString(), useSsl.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticExceptionLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool exceptionLogged = false;
bool responseLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable(s => !s.Contains("HttpRequestOut"));
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync($"http://_{Guid.NewGuid().ToString("N")}.com"))
.GetAwaiter().GetResult();
Assert.True(exceptionLogged, "Exception was not logged");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[ActiveIssue(23209)]
[Fact]
public void SendAsync_ExpectedDiagnosticCancelledLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool cancelLogged = false;
var diagnosticListenerObserver = new FakeDiagnosticListenerObserver(kvp =>
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable(s => !s.Contains("HttpRequestOut"));
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
LoopbackServer.CreateServerAsync(async (server, url) =>
{
WaitForTrue(() => Volatile.Read(ref cancelLogged), TimeSpan.FromSeconds(1),
"Cancellation was not logged within 1 second timeout.");
diagnosticListenerObserver.Disable();
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[Fact]
public void SendAsync_ExpectedDiagnosticSourceActivityLoggingRequestId()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool requestLogged = false;
bool responseLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable(s => s.Contains("HttpRequestOut"));
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
LoopbackServer.CreateServerAsync(async (server, url) =>
{
Assert.False(responseLogged, "Response was logged when Activity logging was enabled.");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[Fact]
public void SendAsync_ExpectedDiagnosticSourceActivityLoggingW3C()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool requestLogged = false;
bool responseLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable(s => s.Contains("HttpRequestOut"));
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
LoopbackServer.CreateServerAsync(async (server, url) =>
{
Assert.False(responseLogged, "Response was logged when Activity logging was enabled.");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticSourceActivityLogging_InvalidBaggage()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool activityStopLogged = false;
bool exceptionLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable(s => s.Contains("HttpRequestOut"));
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
client.GetAsync(Configuration.Http.RemoteEchoServer).Result.Dispose();
}
Assert.False(exceptionLogged, "Exception was logged for successful request");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticSourceActivityLoggingDoesNotOverwriteHeader()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool activityStartLogged = false;
bool activityStopLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable();
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
client.GetAsync(Configuration.Http.RemoteEchoServer).Result.Dispose();
}
"HttpRequestOut.Stop was not logged within 1 second timeout.");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
public void SendAsync_ExpectedDiagnosticSourceActivityLoggingDoesNotOverwriteW3CTraceParentHeader()
{
Assert.False(UseHttp2, "The test currently ignores UseHttp2.");
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool activityStartLogged = false;
bool activityStopLogged = false;
{
diagnosticListenerObserver.Enable();
using (var request = new HttpRequestMessage(HttpMethod.Get, Configuration.Http.RemoteEchoServer))
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
request.Headers.Add("traceparent", customTraceParentHeader);
client.SendAsync(request).Result.Dispose();
"HttpRequestOut.Stop was not logged within 1 second timeout.");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticSourceUrlFilteredActivityLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool activityStartLogged = false;
bool activityStopLogged = false;
return true;
});
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
client.GetAsync(Configuration.Http.RemoteEchoServer).Result.Dispose();
}
Assert.False(activityStopLogged, "HttpRequestOut.Stop was logged while URL disabled.");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticExceptionActivityLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool exceptionLogged = false;
bool activityStopLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable();
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync($"http://_{Guid.NewGuid().ToString("N")}.com"))
.GetAwaiter().GetResult();
Assert.True(exceptionLogged, "Exception was not logged");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticSynchronousExceptionActivityLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool exceptionLogged = false;
bool activityStopLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable();
- using (HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClientHandler handler = CreateHttpClientHandler(useHttp2String))
using (HttpClient client = CreateHttpClient(handler, useHttp2String))
{
// Set a https proxy.
HttpRequestMessage request =
new HttpRequestMessage(HttpMethod.Get, $"http://_{Guid.NewGuid().ToString("N")}.com");
- if (bool.Parse(useSocketsHttpHandlerString))
- {
- // Forces a synchronous exception for SocketsHttpHandler.
- // SocketsHttpHandler only allow http scheme for proxies.
-
- // We cannot use Assert.Throws<Exception>(() => { SendAsync(...); }) to verify the
- // synchronous exception here, because DiagnosticsHandler SendAsync() method has async
- // modifier, and returns Task. If the call is not awaited, the current test method will continue
- // run before the call is completed, thus Assert.Throws() will not capture the exception.
- // We need to wait for the Task to complete synchronously, to validate the exception.
- Task sendTask = client.SendAsync(request);
- Assert.True(sendTask.IsFaulted);
- Assert.IsType<NotSupportedException>(sendTask.Exception.InnerException);
- }
- else
- {
- // Forces a synchronous exception for WinHttpHandler.
- // WinHttpHandler will not allow (proxy != null && !UseCustomProxy).
- handler.UseProxy = false;
-
- // We cannot use Assert.Throws<Exception>(() => { SendAsync(...); }) to verify the
- // synchronous exception here, because DiagnosticsHandler SendAsync() method has async
- // modifier, and returns Task. If the call is not awaited, the current test method will continue
- // run before the call is completed, thus Assert.Throws() will not capture the exception.
- // We need to wait for the Task to complete synchronously, to validate the exception.
- Task sendTask = client.SendAsync(request);
- Assert.True(sendTask.IsFaulted);
- Assert.IsType<InvalidOperationException>(sendTask.Exception.InnerException);
- }
+ // Forces a synchronous exception for SocketsHttpHandler.
+ // SocketsHttpHandler only allow http scheme for proxies.
+
+ // We cannot use Assert.Throws<Exception>(() => { SendAsync(...); }) to verify the
+ // synchronous exception here, because DiagnosticsHandler SendAsync() method has async
+ // modifier, and returns Task. If the call is not awaited, the current test method will continue
+ // run before the call is completed, thus Assert.Throws() will not capture the exception.
+ // We need to wait for the Task to complete synchronously, to validate the exception.
+ Task sendTask = client.SendAsync(request);
+ Assert.True(sendTask.IsFaulted);
+ Assert.IsType<NotSupportedException>(sendTask.Exception.InnerException);
}
// Poll with a timeout since logging response is not synchronized with returning a response.
Assert.True(exceptionLogged, "Exception was not logged");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticSourceNewAndDeprecatedEventsLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool requestLogged = false;
bool responseLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable();
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
client.GetAsync(Configuration.Http.RemoteEchoServer).Result.Dispose();
}
Assert.True(responseLogged, "Response was not logged.");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticExceptionOnlyActivityLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool exceptionLogged = false;
bool activityLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable(s => s.Equals("System.Net.Http.Exception"));
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync($"http://_{Guid.NewGuid().ToString("N")}.com"))
.GetAwaiter().GetResult();
Assert.False(activityLogged, "HttpOutReq was logged when logging was disabled");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticStopOnlyActivityLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool activityStartLogged = false;
bool activityStopLogged = false;
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable(s => s.Equals("System.Net.Http.HttpRequestOut"));
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
client.GetAsync(Configuration.Http.RemoteEchoServer).Result.Dispose();
}
"HttpRequestOut.Start was logged when start logging was disabled");
diagnosticListenerObserver.Disable();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedActivityPropagationWithoutListener()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
Activity parent = new Activity("parent").Start();
using HttpResponseMessage response = client.GetAsync(Configuration.Http.RemoteEchoServer).Result;
Assert.True(response.RequestMessage.Headers.Contains(parent.IdFormat == ActivityIdFormat.Hierarchical ? "Request-Id" : "traceparent"));
parent.Stop();
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedActivityPropagationWithoutListenerOrParentActivity()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
using HttpResponseMessage response = client.GetAsync(Configuration.Http.RemoteEchoServer).Result;
Assert.False(response.RequestMessage.Headers.Contains("tracestate"));
Assert.False(response.RequestMessage.Headers.Contains("Correlation-Context"));
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[OuterLoop("Uses external server")]
[Fact]
public void SendAsync_ExpectedDiagnosticCancelledActivityLogging()
{
- RemoteExecutor.Invoke((useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(useHttp2String =>
{
bool cancelLogged = false;
var diagnosticListenerObserver = new FakeDiagnosticListenerObserver(kvp =>
using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver))
{
diagnosticListenerObserver.Enable();
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
LoopbackServer.CreateServerAsync(async (server, url) =>
{
WaitForTrue(() => Volatile.Read(ref cancelLogged), TimeSpan.FromSeconds(1),
"Cancellation was not logged within 1 second timeout.");
diagnosticListenerObserver.Disable();
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[Fact]
{
public class HPackTest : HttpClientHandlerTestBase
{
- protected override bool UseSocketsHttpHandler => true;
protected override bool UseHttp2 => true;
public HPackTest(ITestOutputHelper output) : base(output)
[MemberData(nameof(GetSelectedSites))]
public async Task RetrieveSite_Succeeds(string site)
{
- // Not doing this in bulk for platform handlers.
- if (!UseSocketsHttpHandler)
- return;
-
int remainingAttempts = 2;
while (remainingAttempts-- > 0)
{
private HttpClient CreateHttpClientForSiteVisit()
{
- HttpClient httpClient = CreateHttpClient(CreateHttpClientHandler(UseSocketsHttpHandler));
+ HttpClient httpClient = CreateHttpClient(CreateHttpClientHandler());
// Some extra headers since some sites only give proper responses when they are present.
httpClient.DefaultRequestHeaders.Add(
[InlineData("WWW-Authenticate: Digest realm=\"hello1\", nonce=\"hello\", algorithm=MD5\r\nWWW-Authenticate: Digest realm=\"hello\", nonce=\"hello\", algorithm=MD5\r\n")]
public async Task HttpClientHandler_MultipleAuthenticateHeaders_WithSameAuth_Succeeds(string authenticateHeader)
{
- if (IsWinHttpHandler)
- {
- // TODO: #28065: Fix failing authentication test cases on different httpclienthandlers.
- return;
- }
-
await HttpClientHandler_MultipleAuthenticateHeaders_Succeeds(authenticateHeader);
}
[Fact]
public async Task PreAuthenticate_SuccessfulBasic_ThenDigestChallenged()
{
- if (IsWinHttpHandler)
- {
- // WinHttpHandler fails with Unauthorized after the basic preauth fails.
- return;
- }
-
await LoopbackServer.CreateClientAndServerAsync(async uri =>
{
using (HttpClientHandler handler = CreateHttpClientHandler())
[ConditionalFact(nameof(IsDomainJoinedServerAvailable))]
public async Task Credentials_DomainJoinedServerUsesKerberos_UseIpAddressAndHostHeader_Success()
{
- if (IsWinHttpHandler)
- {
- throw new SkipTestException("Skipping test on platform handlers (CurlHandler, WinHttpHandler)");
- }
-
using (HttpClientHandler handler = CreateHttpClientHandler())
using (HttpClient client = CreateHttpClient(handler))
{
[Theory, MemberData(nameof(RemoteServersAndRedirectStatusCodes))]
public async Task GetAsync_AllowAutoRedirectFalse_RedirectFromHttpToHttp_StatusCodeRedirect(Configuration.Http.RemoteServer remoteServer, int statusCode)
{
- if (statusCode == 308 && (IsWinHttpHandler && PlatformDetection.WindowsVersion < 10))
- {
- // 308 redirects are not supported on old versions of WinHttp, or on .NET Framework.
- return;
- }
-
HttpClientHandler handler = CreateHttpClientHandler();
handler.AllowAutoRedirect = false;
using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer, handler))
public async Task AllowAutoRedirect_True_ValidateNewMethodUsedOnRedirection(
int statusCode, string oldMethod, string newMethod)
{
- if (statusCode == 308 && (IsWinHttpHandler && PlatformDetection.WindowsVersion < 10))
- {
- // 308 redirects are not supported on old versions of WinHttp, or on .NET Framework.
- return;
- }
-
HttpClientHandler handler = CreateHttpClientHandler();
using (HttpClient client = CreateHttpClient(handler))
{
[InlineData(303)]
public async Task AllowAutoRedirect_True_PostToGetDoesNotSendTE(int statusCode)
{
- if (IsWinHttpHandler)
- {
- // ISSUE #27440:
- // This test occasionally fails on WinHttpHandler.
- // Likely this is due to the way the loopback server is sending the response before reading the entire request.
- // We should change the server behavior here.
- return;
- }
-
HttpClientHandler handler = CreateHttpClientHandler();
using (HttpClient client = CreateHttpClient(handler))
{
[Theory, MemberData(nameof(RemoteServersAndRedirectStatusCodes))]
public async Task GetAsync_AllowAutoRedirectTrue_RedirectFromHttpToHttp_StatusCodeOK(Configuration.Http.RemoteServer remoteServer, int statusCode)
{
- if (statusCode == 308 && (IsWinHttpHandler && PlatformDetection.WindowsVersion < 10))
- {
- // 308 redirects are not supported on old versions of WinHttp, or on .NET Framework.
- return;
- }
-
HttpClientHandler handler = CreateHttpClientHandler();
handler.AllowAutoRedirect = true;
using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer, handler))
[Fact]
public async Task GetAsync_AllowAutoRedirectTrue_RedirectWithoutLocation_ReturnsOriginalResponse()
{
- // [ActiveIssue(24819, TestPlatforms.Windows)]
- if (IsWinHttpHandler)
- {
- return;
- }
-
HttpClientHandler handler = CreateHttpClientHandler();
handler.AllowAutoRedirect = true;
using (HttpClient client = CreateHttpClient(handler))
[InlineData(3, 4)]
public async Task GetAsync_MaxAutomaticRedirectionsNServerHops_ThrowsIfTooMany(int maxHops, int hops)
{
- if (IsWinHttpHandler && !PlatformDetection.IsWindows10Version1703OrGreater)
- {
- // Skip this test if using WinHttpHandler but on a release prior to Windows 10 Creators Update.
- _output.WriteLine("Skipping test due to Windows 10 version prior to Version 1703.");
- return;
- }
-
HttpClientHandler handler = CreateHttpClientHandler();
handler.MaxAutomaticRedirections = maxHops;
using (HttpClient client = CreateHttpClient(handler))
}
else
{
- if (UseSocketsHttpHandler)
- {
- using (HttpResponseMessage response = await t)
- {
- Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
- }
- }
- else
+ using (HttpResponseMessage response = await t)
{
- await Assert.ThrowsAsync<HttpRequestException>(() => t);
+ Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
}
}
}
public async Task GetAsync_AllowAutoRedirectTrue_RetainsOriginalFragmentIfAppropriate(
string origFragment, string redirFragment, string expectedFragment, bool useRelativeRedirect)
{
- if (IsWinHttpHandler)
- {
- // According to https://tools.ietf.org/html/rfc7231#section-7.1.2,
- // "If the Location value provided in a 3xx (Redirection) response does
- // not have a fragment component, a user agent MUST process the
- // redirection as if the value inherits the fragment component of the
- // URI reference used to generate the request target(i.e., the
- // redirection inherits the original reference's fragment, if any)."
- // WINHTTP is not doing this, and thus neither is WinHttpHandler.
- // It also sometimes doesn't include the fragments for redirects
- // even in other cases.
- return;
- }
-
HttpClientHandler handler = CreateHttpClientHandler();
handler.AllowAutoRedirect = true;
using (HttpClient client = CreateHttpClient(handler))
[Theory, MemberData(nameof(RemoteServersAndRedirectStatusCodes))]
public async Task GetAsync_CredentialIsCredentialCacheUriRedirect_StatusCodeOK(Configuration.Http.RemoteServer remoteServer, int statusCode)
{
- if (statusCode == 308 && (IsWinHttpHandler && PlatformDetection.WindowsVersion < 10))
- {
- // 308 redirects are not supported on old versions of WinHttp, or on .NET Framework.
- return;
- }
-
Uri uri = remoteServer.BasicAuthUriForCreds(userName: Username, password: Password);
Uri redirectUri = remoteServer.RedirectUriForCreds(
statusCode: statusCode,
[Theory, MemberData(nameof(RemoteServersAndRedirectStatusCodes))]
public async Task DefaultHeaders_SetCredentials_ClearedOnRedirect(Configuration.Http.RemoteServer remoteServer, int statusCode)
{
- if (statusCode == 308 && (IsWinHttpHandler && PlatformDetection.WindowsVersion < 10))
- {
- // 308 redirects are not supported on old versions of WinHttp, or on .NET Framework.
- return;
- }
-
HttpClientHandler handler = CreateHttpClientHandler();
using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer, handler))
{
[InlineData(true, CancellationMode.Token)]
public async Task PostAsync_CancelDuringRequestContentSend_TaskCanceledQuickly(bool chunkedTransfer, CancellationMode mode)
{
- if (!UseSocketsHttpHandler)
- {
- // Issue #27063: hangs / doesn't cancel
- return;
- }
-
if (LoopbackServerFactory.IsHttp2 && chunkedTransfer)
{
// There is no chunked encoding in HTTP/2
[Fact]
public async Task GetAsyncWithBasicAuth_ReceiveSetCookie_CookieSent()
{
- if (IsWinHttpHandler)
- {
- // Issue #26986
- // WinHttpHandler does not process the cookie.
- return;
- }
-
await LoopbackServerFactory.CreateClientAndServerAsync(async url =>
{
HttpClientHandler handler = CreateHttpClientHandler();
public async Task DecompressedResponse_MethodSpecified_DecompressedContentReturned(
string encodingName, Func<Stream, Stream> compress, DecompressionMethods methods)
{
- if (!UseSocketsHttpHandler && encodingName == "br")
- {
- // Brotli only supported on SocketsHttpHandler.
- return;
- }
-
var expectedContent = new byte[12345];
new Random(42).NextBytes(expectedContent);
string encodings,
string manualAcceptEncodingHeaderValues)
{
- if (!UseSocketsHttpHandler &&
- (encodings.Contains("br") || manualAcceptEncodingHeaderValues.Contains("br")))
- {
- // Brotli encoding only supported on SocketsHttpHandler.
- return;
- }
-
await LoopbackServer.CreateServerAsync(async (server, url) =>
{
HttpClientHandler handler = CreateHttpClientHandler();
psi.Environment.Add("http_proxy", $"http://{proxyUri.Host}:{proxyUri.Port}");
}
- RemoteExecutor.Invoke(async (useProxyString, useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(async (useProxyString, useHttp2String) =>
{
- using (HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClientHandler handler = CreateHttpClientHandler(useHttp2String))
using (HttpClient client = CreateHttpClient(handler, useHttp2String))
{
var creds = new NetworkCredential(ExpectedUsername, ExpectedPassword);
// Correctness of user and password is done in server part.
Assert.True(response.StatusCode == HttpStatusCode.OK);
}
- }, useProxy.ToString(), UseSocketsHttpHandler.ToString(), UseHttp2.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose();
+ }, useProxy.ToString(), UseHttp2.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose();
if (useProxy)
{
await proxyTask;
[Fact]
public async Task SendAsync_GetWithInvalidHostHeader_ThrowsException()
{
- if (!UseSocketsHttpHandler || LoopbackServerFactory.IsHttp2)
+ if (LoopbackServerFactory.IsHttp2)
{
// Only SocketsHttpHandler with HTTP/1.x uses the Host header to influence the SSL auth.
// Host header is not used for HTTP2.
// This class is dedicated to SocketHttpHandler tests specific to HTTP/1.x.
public class HttpClientHandlerTest_Http1 : HttpClientHandlerTestBase
{
- protected override bool UseSocketsHttpHandler => true;
-
public HttpClientHandlerTest_Http1(ITestOutputHelper output) : base(output) { }
[Fact]
{
public abstract class HttpClientHandlerTest_Http2 : HttpClientHandlerTestBase
{
- protected override bool UseSocketsHttpHandler => true;
protected override bool UseHttp2 => true;
public static bool SupportsAlpn => PlatformDetection.SupportsAlpn;
where T : Exception
{
Exception e = await Assert.ThrowsAsync<T>(() => task);
- if (UseSocketsHttpHandler)
- {
- string text = e.ToString();
- Assert.Contains(((int)errorCode).ToString("x"), text);
- Assert.Contains(
- Enum.IsDefined(typeof(ProtocolErrors), errorCode) ? errorCode.ToString() : "(unknown error)",
- text);
- }
+ string text = e.ToString();
+ Assert.Contains(((int)errorCode).ToString("x"), text);
+ Assert.Contains(
+ Enum.IsDefined(typeof(ProtocolErrors), errorCode) ? errorCode.ToString() : "(unknown error)",
+ text);
}
private Task AssertProtocolErrorAsync(Task task, ProtocolErrors errorCode)
[ActiveIssue(35466)]
[ConditionalTheory(nameof(SupportsAlpn))]
- [InlineData(SettingId.MaxFrameSize, 16383, ProtocolErrors.PROTOCOL_ERROR, true)]
- [InlineData(SettingId.MaxFrameSize, 162777216, ProtocolErrors.PROTOCOL_ERROR, true)]
- [InlineData(SettingId.InitialWindowSize, 0x80000000, ProtocolErrors.FLOW_CONTROL_ERROR, false)]
- public async Task Http2_ServerSendsInvalidSettingsValue_Error(SettingId settingId, uint value, ProtocolErrors expectedError, bool skipForWinHttp)
+ [InlineData(SettingId.MaxFrameSize, 16383, ProtocolErrors.PROTOCOL_ERROR)]
+ [InlineData(SettingId.MaxFrameSize, 162777216, ProtocolErrors.PROTOCOL_ERROR)]
+ [InlineData(SettingId.InitialWindowSize, 0x80000000, ProtocolErrors.FLOW_CONTROL_ERROR)]
+ public async Task Http2_ServerSendsInvalidSettingsValue_Error(SettingId settingId, uint value, ProtocolErrors expectedError)
{
- if (IsWinHttpHandler && skipForWinHttp)
- {
- // WinHTTP does not treat these as errors, it seems to ignore the invalid setting.
- return;
- }
-
using (Http2LoopbackServer server = Http2LoopbackServer.CreateServer())
using (HttpClient client = CreateHttpClient())
{
[ConditionalFact(nameof(SupportsAlpn))]
public async Task Http2_StreamResetByServerBeforeHeadersSent_RequestFails()
{
- if (IsWinHttpHandler)
- {
- // WinHTTP does not genenerate an exception here.
- // It seems to ignore a RST_STREAM sent before headers are sent, and continue to wait for HEADERS.
- return;
- }
-
using (Http2LoopbackServer server = Http2LoopbackServer.CreateServer())
using (HttpClient client = CreateHttpClient())
{
[ConditionalFact(nameof(SupportsAlpn))]
public async Task DataFrame_IdleStream_ConnectionError()
{
- if (IsWinHttpHandler)
- {
- // WinHTTP does not treat this as an error, it seems to ignore the invalid frame.
- return;
- }
-
using (Http2LoopbackServer server = Http2LoopbackServer.CreateServer())
using (HttpClient client = CreateHttpClient())
{
[ConditionalFact(nameof(SupportsAlpn))]
public async Task HeadersFrame_IdleStream_ConnectionError()
{
- if (IsWinHttpHandler)
- {
- // WinHTTP does not treat this as an error, it seems to ignore the HEADERS frame.
- return;
- }
-
using (Http2LoopbackServer server = Http2LoopbackServer.CreateServer())
using (HttpClient client = CreateHttpClient())
{
[Fact]
public async Task GetAsync_DontDisposeResponse_EventuallyUnblocksWaiters()
{
- if (!UseSocketsHttpHandler)
- {
- // Issue #27067. Hang.
- return;
- }
-
await LoopbackServer.CreateServerAsync(async (server, uri) =>
{
using (HttpClientHandler handler = CreateHttpClientHandler())
Exception e = await Assert.ThrowsAsync<HttpRequestException>(() => getAsync);
cts.Cancel();
- if (UseSocketsHttpHandler)
- {
- Assert.Contains((handler.MaxResponseHeadersLength * 1024).ToString(), e.ToString());
- }
+ Assert.Contains((handler.MaxResponseHeadersLength * 1024).ToString(), e.ToString());
await serverTask;
});
}
else
{
Exception e = await Assert.ThrowsAsync<HttpRequestException>(() => getAsync);
- if (UseSocketsHttpHandler)
- {
- Assert.Contains((handler.MaxResponseHeadersLength * 1024).ToString(), e.ToString());
- }
+ Assert.Contains((handler.MaxResponseHeadersLength * 1024).ToString(), e.ToString());
try { await serverTask; } catch { }
}
});
bool secureServer,
bool proxyClosesConnectionAfterFirst407Response)
{
- if (PlatformDetection.IsWindowsNanoServer && IsWinHttpHandler && proxyAuthScheme == AuthenticationSchemes.Digest)
- {
- // WinHTTP doesn't support Digest very well and is disabled on Nano.
- return;
- }
-
if (!PlatformDetection.IsWindows &&
(proxyAuthScheme == AuthenticationSchemes.Negotiate || proxyAuthScheme == AuthenticationSchemes.Ntlm))
{
[ConditionalFact]
public void Proxy_UseEnvironmentVariableToSetSystemProxy_RequestGoesThruProxy()
{
- if (!UseSocketsHttpHandler)
- {
- throw new SkipTestException("Test needs SocketsHttpHandler");
- }
-
- RemoteExecutor.Invoke(async (useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(async (useHttp2String) =>
{
var options = new LoopbackProxyServer.Options { AddViaRequestHeader = true };
using (LoopbackProxyServer proxyServer = LoopbackProxyServer.Create(options))
{
Environment.SetEnvironmentVariable("http_proxy", proxyServer.Uri.AbsoluteUri.ToString());
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
using (HttpResponseMessage response = await client.GetAsync(Configuration.Http.RemoteEchoServer))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Contains(proxyServer.ViaHeader, body);
}
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[ActiveIssue(32809)]
{
handler.Proxy = new WebProxy("https://" + Guid.NewGuid().ToString("N"));
- Type expectedType = UseSocketsHttpHandler ?
- typeof(NotSupportedException) :
- typeof(HttpRequestException);
-
- await Assert.ThrowsAsync(expectedType, () => client.GetAsync("http://" + Guid.NewGuid().ToString("N")));
+ await Assert.ThrowsAsync<NotSupportedException>(() => client.GetAsync("http://" + Guid.NewGuid().ToString("N")));
}
}
}
[Fact]
+ [PlatformSpecific(TestPlatforms.Windows)]
public async Task MultiProxy_PAC_Failover_Succeeds()
{
- if (!UseSocketsHttpHandler || !PlatformDetection.IsWindows)
- {
- // PAC-based failover is only supported on Windows/SocketsHttpHandler
- return;
- }
-
// Create our failing proxy server.
// Bind a port to reserve it, but don't start listening yet. The first Connect() should fail and cause a fail-over.
using Socket failingProxyServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
[Fact]
public async Task UseCallback_HaveCredsAndUseAuthenticatedCustomProxyAndPostToSecureServer_Success()
{
- if (IsWinHttpHandler && PlatformDetection.IsWindows7)
- {
- // Issue #27612
- return;
- }
-
var options = new LoopbackProxyServer.Options
{ AuthenticationSchemes = AuthenticationSchemes.Basic,
ConnectionCloseAfter407 = true
[ConditionalFact(nameof(ClientSupportsDHECipherSuites))]
public async Task NoCallback_RevokedCertificate_NoRevocationChecking_Succeeds()
{
- try
- {
- using (HttpClient client = CreateHttpClient())
- using (HttpResponseMessage response = await client.GetAsync(Configuration.Http.RevokedCertRemoteServer))
- {
- Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- }
- }
- catch (HttpRequestException)
+ using (HttpClient client = CreateHttpClient())
+ using (HttpResponseMessage response = await client.GetAsync(Configuration.Http.RevokedCertRemoteServer))
{
- if (UseSocketsHttpHandler)
- throw;
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
new object[] { Configuration.Http.WrongHostNameCertRemoteServer , SslPolicyErrors.RemoteCertificateNameMismatch},
};
- private async Task UseCallback_BadCertificate_ExpectedPolicyErrors_Helper(string url, string useSocketsHttpHandlerString, string useHttp2String, SslPolicyErrors expectedErrors)
+ private async Task UseCallback_BadCertificate_ExpectedPolicyErrors_Helper(string url, string useHttp2String, SslPolicyErrors expectedErrors)
{
- HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String);
+ HttpClientHandler handler = CreateHttpClientHandler(useHttp2String);
using (HttpClient client = CreateHttpClient(handler, useHttp2String))
{
bool callbackCalled = false;
try
{
- await UseCallback_BadCertificate_ExpectedPolicyErrors_Helper(url, UseSocketsHttpHandler.ToString(), UseHttp2.ToString(), expectedErrors);
+ await UseCallback_BadCertificate_ExpectedPolicyErrors_Helper(url, UseHttp2.ToString(), expectedErrors);
}
catch (HttpRequestException e) when (e.InnerException?.GetType().Name == "WinHttpException" &&
e.InnerException.HResult == SEC_E_BUFFER_TOO_SMALL &&
{
// We set SSL_CERT_DIR and SSL_CERT_FILE to empty locations.
// The HttpClient should fail to validate the server certificate.
-
var psi = new ProcessStartInfo();
string sslCertDir = GetTestFilePath();
Directory.CreateDirectory(sslCertDir);
File.WriteAllText(sslCertFile, "");
psi.Environment.Add("SSL_CERT_FILE", sslCertFile);
- RemoteExecutor.Invoke(async (useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(async (useHttp2String) =>
{
const string Url = "https://www.microsoft.com";
- using (HttpClient client = CreateHttpClient(useSocketsHttpHandlerString, useHttp2String))
+ using (HttpClient client = CreateHttpClient(useHttp2String))
{
await Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync(Url));
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose();
+ }, UseHttp2.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose();
}
}
}
[MemberData(nameof(SupportedSSLVersionServers))]
public async Task GetAsync_SupportedSSLVersion_Succeeds(SslProtocols sslProtocols, string url)
{
- if (UseSocketsHttpHandler)
- {
- // TODO #26186: SocketsHttpHandler is failing on some OSes.
- return;
- }
-
using (HttpClientHandler handler = CreateHttpClientHandler())
{
handler.SslProtocols = sslProtocols;
public async Task GetAsync_AllowedClientSslVersionDiffersFromServer_ThrowsException(
SslProtocols allowedClientProtocols, SslProtocols acceptedServerProtocols)
{
- if (IsWinHttpHandler &&
- allowedClientProtocols == (SslProtocols.Tls11 | SslProtocols.Tls12) &&
- acceptedServerProtocols == SslProtocols.Tls)
- {
- // Native WinHTTP sometimes uses multiple TCP connections to try other TLS protocols when
- // getting TLS protocol failures as part of its TLS fallback algorithm. The loopback server
- // doesn't expect this and stops listening for more connections. This causes unexpected test
- // failures. See dotnet/corefx #8538.
- return;
- }
-
using (HttpClientHandler handler = CreateHttpClientHandler())
using (HttpClient client = CreateHttpClient(handler))
{
[OuterLoop("Uses external server")]
public async Task ProxyTunnelRequest_UserAgentHeaderAdded(bool addUserAgentHeader)
{
- if (!UseSocketsHttpHandler)
- {
- return; // Skip test since the fix is only in SocketsHttpHandler.
- }
-
string addressUri = $"https://{Configuration.Http.SecureHost}/";
bool connectionAccepted = false;
[Fact]
public async Task GetAsync_ServerNeedsAuthAndNoCredential_StatusCodeUnauthorized()
{
- using (HttpClient client = CreateHttpClient(UseSocketsHttpHandler.ToString(), UseHttp2.ToString()))
+ using (HttpClient client = CreateHttpClient(UseHttp2.ToString()))
{
Uri uri = Configuration.Http.RemoteHttp11Server.BasicAuthUriForCreds(userName: Username, password: Password);
using (HttpResponseMessage response = await client.GetAsync(uri))
[MemberData(nameof(RemoteServersAndHeaderEchoUrisMemberData))]
public async Task GetAsync_RequestHeadersAddCustomHeaders_HeaderAndEmptyValueSent(Configuration.Http.RemoteServer remoteServer, Uri uri)
{
- if (IsWinHttpHandler && !PlatformDetection.IsWindows10Version1709OrGreater)
- {
- return;
- }
-
string name = "X-Cust-Header-NoValue";
string value = "";
using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer))
[InlineData(true, true)]
public async Task GetAsync_IncompleteData_ThrowsHttpRequestException(bool failDuringHeaders, bool getString)
{
- if (IsWinHttpHandler)
- {
- // [ActiveIssue(39136)]
- return;
- }
-
await LoopbackServer.CreateClientAndServerAsync(async uri =>
{
using (HttpClient client = CreateHttpClient())
[Fact]
public async Task PostAsync_ManyDifferentRequestHeaders_SentCorrectly()
{
- if (IsWinHttpHandler)
- {
- // Issue #27171
- // Fails consistently with:
- // System.InvalidCastException: "Unable to cast object of type 'System.Object[]' to type 'System.Net.Http.WinHttpRequestState'"
- // This appears to be due to adding the Expect: 100-continue header, which causes winhttp
- // to fail with a "The parameter is incorrect" error, which in turn causes the request to
- // be torn down, and in doing so, we handle this during disposal of the SafeWinHttpHandle.
- return;
- }
-
const string content = "hello world";
// Using examples from https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields
using (HttpResponseMessage response = await client.SendAsync(req))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- if (UseSocketsHttpHandler)
+
+ const string ExpectedReqHeader = "\"Expect\": \"100-continue\"";
+ if (expectContinue == true && (version == "1.1" || version == "2.0"))
{
- const string ExpectedReqHeader = "\"Expect\": \"100-continue\"";
- if (expectContinue == true && (version == "1.1" || version == "2.0"))
- {
- Assert.Contains(ExpectedReqHeader, await response.Content.ReadAsStringAsync());
- }
- else
- {
- Assert.DoesNotContain(ExpectedReqHeader, await response.Content.ReadAsStringAsync());
- }
+ Assert.Contains(ExpectedReqHeader, await response.Content.ReadAsStringAsync());
+ }
+ else
+ {
+ Assert.DoesNotContain(ExpectedReqHeader, await response.Content.ReadAsStringAsync());
}
}
}
[ConditionalFact]
public async Task SendAsync_101SwitchingProtocolsResponse_Success()
{
- // WinHttpHandler and CurlHandler will hang, waiting for additional response.
- // Other handlers will accept 101 as a final response.
- if (IsWinHttpHandler) return;
-
if (LoopbackServerFactory.IsHttp2)
{
throw new SkipTestException("Upgrade is not supported on HTTP/2");
using (HttpResponseMessage response = await client.SendAsync(request))
{
- if (method == "TRACE" && (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || UseSocketsHttpHandler))
+ if (method == "TRACE")
{
// .NET Framework also allows the HttpWebRequest and HttpClient APIs to send a request using 'TRACE'
// verb and a request body. The usual response from a server is "400 Bad Request".
[OuterLoop("Uses external server")]
[Fact]
+ [ActiveIssue(339)]
public async Task SendAsync_RequestVersionNotSpecified_ServerReceivesVersion11Request()
{
- // SocketsHttpHandler treats 0.0 as a bad version, and throws.
- if (UseSocketsHttpHandler)
- {
- return;
- }
-
// The default value for HttpRequestMessage.Version is Version(1,1).
// So, we need to set something different (0,0), to test the "unknown" version.
Version receivedRequestVersion = await SendRequestAndGetRequestVersionAsync(new Version(0, 0));
[MemberData(nameof(Http2Servers))]
public async Task SendAsync_RequestVersion20_ResponseVersion20IfHttp2Supported(Uri server)
{
- if (IsWinHttpHandler && !PlatformDetection.IsWindows10Version1703OrGreater)
- {
- // Skip this test if running on Windows but on a release prior to Windows 10 Creators Update.
- throw new SkipTestException("Skipping test due to Windows 10 version prior to Version 1703.");
- }
// We don't currently have a good way to test whether HTTP/2 is supported without
// using the same mechanism we're trying to test, so for now we allow both 2.0 and 1.1 responses.
var request = new HttpRequestMessage(HttpMethod.Get, server);
{
public readonly ITestOutputHelper _output;
- protected virtual bool UseSocketsHttpHandler => true;
protected virtual bool UseHttp2 => false;
- protected bool IsWinHttpHandler => !UseSocketsHttpHandler && PlatformDetection.IsWindows;
-
public HttpClientHandlerTestBase(ITestOutputHelper output)
{
_output = output;
protected HttpClient CreateHttpClient(HttpMessageHandler handler) =>
new HttpClient(handler) { DefaultRequestVersion = VersionFromUseHttp2 };
- protected static HttpClient CreateHttpClient(string useSocketsHttpHandlerBoolString, string useHttp2String) =>
- CreateHttpClient(CreateHttpClientHandler(useSocketsHttpHandlerBoolString, useHttp2String), useHttp2String);
+ protected static HttpClient CreateHttpClient(string useHttp2String) =>
+ CreateHttpClient(CreateHttpClientHandler(useHttp2String), useHttp2String);
protected static HttpClient CreateHttpClient(HttpMessageHandler handler, string useHttp2String) =>
new HttpClient(handler) { DefaultRequestVersion = GetVersion(bool.Parse(useHttp2String)) };
- protected HttpClientHandler CreateHttpClientHandler() => CreateHttpClientHandler(UseSocketsHttpHandler, UseHttp2);
+ protected HttpClientHandler CreateHttpClientHandler() => CreateHttpClientHandler(UseHttp2);
- protected static HttpClientHandler CreateHttpClientHandler(string useSocketsHttpHandlerBoolString, string useHttp2LoopbackServerString) =>
- CreateHttpClientHandler(bool.Parse(useSocketsHttpHandlerBoolString), bool.Parse(useHttp2LoopbackServerString));
+ protected static HttpClientHandler CreateHttpClientHandler(string useHttp2LoopbackServerString) =>
+ CreateHttpClientHandler(bool.Parse(useHttp2LoopbackServerString));
- protected static HttpClientHandler CreateHttpClientHandler(bool useSocketsHttpHandler, bool useHttp2LoopbackServer = false)
+ protected static HttpClientHandler CreateHttpClientHandler(bool useHttp2LoopbackServer = false)
{
- HttpClientHandler handler;
-
- if (useSocketsHttpHandler)
- {
- handler = new HttpClientHandler();
- }
- else
- {
- // Create platform specific handler.
- ConstructorInfo ctor = typeof(HttpClientHandler).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(bool) }, null);
- Debug.Assert(ctor != null, "Couldn't find test constructor on HttpClientHandler");
-
- handler = (HttpClientHandler)ctor.Invoke(new object[] { useSocketsHttpHandler });
- Debug.Assert(useSocketsHttpHandler == IsSocketsHttpHandler(handler), "Unexpected handler.");
- }
+ HttpClientHandler handler = new HttpClientHandler();
if (useHttp2LoopbackServer)
{
return handler;
}
- protected static bool IsSocketsHttpHandler(HttpClientHandler handler) =>
- GetUnderlyingSocketsHttpHandler(handler) != null;
-
protected static object GetUnderlyingSocketsHttpHandler(HttpClientHandler handler)
{
FieldInfo field = typeof(HttpClientHandler).GetField("_socketsHttpHandler", BindingFlags.Instance | BindingFlags.NonPublic);
// ActiveIssue #39293: WinHttpHandler will downgrade to 1.1 if you set Transfer-Encoding: chunked.
// So, skip this verification if we're not using SocketsHttpHandler.
- if (PlatformDetection.SupportsAlpn && IsSocketsHttpHandler(httpClientHandler))
+ if (PlatformDetection.SupportsAlpn)
{
wrappedHandler = new VersionCheckerHttpHandler(httpClientHandler, remoteServer.HttpVersion);
}
public sealed class SocketsHttpHandler_HttpClientMiniStress_NoVersion : HttpClientMiniStress
{
public SocketsHttpHandler_HttpClientMiniStress_NoVersion(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
[ConditionalTheory(typeof(TestEnvironment), nameof(TestEnvironment.IsStressModeEnabled))]
[InlineData(1000000)]
public sealed class SocketsHttpHandler_HttpClientMiniStress_Http2 : HttpClientMiniStress
{
public SocketsHttpHandler_HttpClientMiniStress_Http2(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
protected override bool UseHttp2 => true;
}
public sealed class SocketsHttpHandler_HttpClientMiniStress_Http11 : HttpClientMiniStress
{
public SocketsHttpHandler_HttpClientMiniStress_Http11(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
[ConditionalTheory(typeof(TestEnvironment), nameof(TestEnvironment.IsStressModeEnabled))]
[MemberData(nameof(PostStressOptions))]
[InlineData(9)]
public async Task GetAsync_RequestVersion0X_ThrowsOr11(int minorVersion)
{
- Type exceptionType = null;
- if (UseSocketsHttpHandler)
- {
- exceptionType = typeof(NotSupportedException);
- }
-
await LoopbackServer.CreateServerAsync(async (server, url) =>
{
using (HttpClient client = CreateHttpClient())
Task<HttpResponseMessage> getResponseTask = client.SendAsync(request);
Task<List<string>> serverTask = server.AcceptConnectionSendResponseAndCloseAsync();
-
- if (exceptionType == null)
- {
- await TestHelper.WhenAllCompletedOrAnyFailed(getResponseTask, serverTask);
- var requestLines = await serverTask;
- Assert.Equal($"GET {url.PathAndQuery} HTTP/1.1", requestLines[0]);
- }
- else
- {
- await Assert.ThrowsAsync(exceptionType, (() => TestHelper.WhenAllCompletedOrAnyFailed(getResponseTask, serverTask)));
- }
+ await Assert.ThrowsAsync<NotSupportedException>(() => TestHelper.WhenAllCompletedOrAnyFailed(getResponseTask, serverTask));
}
}, new LoopbackServer.Options { StreamWrapper = GetStream_ClientDisconnectOk});
}
[InlineData(7)]
public async Task GetAsync_ResponseUnknownVersion1X_Success(int responseMinorVersion)
{
- bool reportAs00 = !UseSocketsHttpHandler;
-
await LoopbackServer.CreateServerAsync(async (server, url) =>
{
using (HttpClient client = CreateHttpClient())
using (HttpResponseMessage response = await getResponseTask)
{
- if (reportAs00)
- {
- Assert.Equal(0, response.Version.Major);
- Assert.Equal(0, response.Version.Minor);
- }
- else
- {
- Assert.Equal(1, response.Version.Major);
- Assert.Equal(responseMinorVersion, response.Version.Minor);
- }
+ Assert.Equal(1, response.Version.Major);
+ Assert.Equal(responseMinorVersion, response.Version.Minor);
}
}
}, new LoopbackServer.Options { StreamWrapper = GetStream });
[InlineData("HTTP/1.1 600 still valid", 600, "still valid")]
public async Task GetAsync_ExpectedStatusCodeAndReason_Success(string statusLine, int expectedStatusCode, string expectedReason)
{
- if (IsWinHttpHandler)
- {
- return; // [ActiveIssue(25880)]
- }
-
await GetAsyncSuccessHelper(statusLine, expectedStatusCode, expectedReason);
}
[Theory]
- [InlineData("HTTP/1.1 200 ", 200, " ", "")]
- [InlineData("HTTP/1.1 200 Something", 200, " Something", "Something")]
- public async Task GetAsync_ExpectedStatusCodeAndReason_PlatformBehaviorTest(string statusLine,
- int expectedStatusCode, string reasonWithSpace, string reasonNoSpace)
+ [InlineData("HTTP/1.1 200 ", 200, " ")]
+ [InlineData("HTTP/1.1 200 Something", 200, " Something")]
+ public async Task GetAsync_ExpectedStatusCodeAndReason_PlatformBehaviorTest(string statusLine, int expectedStatusCode, string reasonWithSpace)
{
- if (UseSocketsHttpHandler)
- {
- // SocketsHttpHandler and .NET Framework will keep the space characters.
- await GetAsyncSuccessHelper(statusLine, expectedStatusCode, reasonWithSpace);
- }
- else
- {
- // WinHttpHandler will trim space characters.
- await GetAsyncSuccessHelper(statusLine, expectedStatusCode, reasonNoSpace);
- }
+ // SocketsHttpHandler and .NET Framework will keep the space characters.
+ await GetAsyncSuccessHelper(statusLine, expectedStatusCode, reasonWithSpace);
}
[Theory]
[InlineData("HTTP/1.1 200\t")]
public async Task GetAsync_InvalidStatusLine_ThrowsExceptionOnSocketsHttpHandler(string responseString)
{
- if (UseSocketsHttpHandler)
- {
- // SocketsHttpHandler and .NET Framework will throw HttpRequestException.
- await GetAsyncThrowsExceptionHelper(responseString);
- }
- // WinHttpHandler will succeed.
+ // SocketsHttpHandler and .NET Framework will throw HttpRequestException.
+ await GetAsyncThrowsExceptionHelper(responseString);
}
private async Task GetAsyncThrowsExceptionHelper(string responseString)
[MemberData(nameof(GetAsync_Chunked_VaryingSizeChunks_ReceivedCorrectly_MemberData))]
public async Task GetAsync_Chunked_VaryingSizeChunks_ReceivedCorrectly(int maxChunkSize, string lineEnding, bool useCopyToAsync)
{
- if (IsWinHttpHandler)
- {
- // [ActiveIssue(28423)]
- return;
- }
-
- if (!UseSocketsHttpHandler && lineEnding != "\r\n")
- {
- // Some handlers don't deal well with "\n" alone as the line ending
- return;
- }
-
var rand = new Random(42);
byte[] expectedData = new byte[100_000];
rand.NextBytes(expectedData);
[InlineData("HEAD")]
public async Task HttpRequest_BodylessMethod_NoContentLength(string method)
{
- if (IsWinHttpHandler)
- {
- // Some platform handlers differ but we don't take it as failure.
- return;
- }
-
using (HttpClient client = CreateHttpClient())
{
await LoopbackServer.CreateServerAsync(async (server, uri) =>
{
private static readonly string s_simpleContent = "Hello World\r\n";
- private bool IsRetrySupported => !IsWinHttpHandler;
-
public HttpRetryProtocolTests(ITestOutputHelper output) : base(output) { }
[Fact]
public async Task GetAsync_RetryOnConnectionClosed_Success()
{
- if (!IsRetrySupported)
- {
- return;
- }
-
await LoopbackServer.CreateClientAndServerAsync(async url =>
{
using (HttpClient client = CreateHttpClient())
[Fact]
public async Task PostAsyncExpect100Continue_FailsAfterContentSendStarted_Throws()
{
- if (IsWinHttpHandler)
- {
- // WinHttpHandler does not support Expect: 100-continue.
- return;
- }
-
var contentSending = new TaskCompletionSource<bool>();
var connectionClosed = new TaskCompletionSource<bool>();
namespace System.Net.Http.Functional.Tests
{
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public class PlatformHandler_HttpClientHandler : HttpClientHandlerTestBase
{
- protected override bool UseSocketsHttpHandler => false;
-
public PlatformHandler_HttpClientHandler(ITestOutputHelper output) : base(output) { }
[Theory]
[InlineData(false)]
[InlineData(true)]
- [PlatformSpecific(TestPlatforms.Windows)]
public async Task GetAsync_TrailingHeaders_Ignored(bool includeTrailerHeader)
{
await LoopbackServer.CreateServerAsync(async (server, url) =>
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_Asynchrony_Test : HttpClientHandler_Asynchrony_Test
{
public PlatformHandler_HttpClientHandler_Asynchrony_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpProtocolTests : HttpProtocolTests
{
public PlatformHandler_HttpProtocolTests(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpProtocolTests_Dribble : HttpProtocolTests_Dribble
{
public PlatformHandler_HttpProtocolTests_Dribble(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_DiagnosticsTest : DiagnosticsTest
{
public PlatformHandler_DiagnosticsTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClient_SelectedSites_Test : HttpClient_SelectedSites_Test
{
public PlatformHandler_HttpClient_SelectedSites_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientEKUTest : HttpClientEKUTest
{
public PlatformHandler_HttpClientEKUTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
#if NETCOREAPP
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_Decompression_Tests : HttpClientHandler_Decompression_Test
{
public PlatformHandler_HttpClientHandler_Decompression_Tests(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test : HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test
{
public PlatformHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
#endif
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_ClientCertificates_Test : HttpClientHandler_ClientCertificates_Test
{
public PlatformHandler_HttpClientHandler_ClientCertificates_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_DefaultProxyCredentials_Test : HttpClientHandler_DefaultProxyCredentials_Test
{
public PlatformHandler_HttpClientHandler_DefaultProxyCredentials_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_MaxConnectionsPerServer_Test : HttpClientHandler_MaxConnectionsPerServer_Test
{
public PlatformHandler_HttpClientHandler_MaxConnectionsPerServer_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_ServerCertificates_Test : HttpClientHandler_ServerCertificates_Test
{
public PlatformHandler_HttpClientHandler_ServerCertificates_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_PostScenarioTest : PostScenarioTest
{
public PlatformHandler_PostScenarioTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_ResponseStreamTest : ResponseStreamTest
{
public PlatformHandler_ResponseStreamTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_SslProtocols_Test : HttpClientHandler_SslProtocols_Test
{
public PlatformHandler_HttpClientHandler_SslProtocols_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_Proxy_Test : HttpClientHandler_Proxy_Test
{
public PlatformHandler_HttpClientHandler_Proxy_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_SchSendAuxRecordHttpTest : SchSendAuxRecordHttpTest
{
public PlatformHandler_SchSendAuxRecordHttpTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandlerTest : HttpClientHandlerTest
{
public PlatformHandler_HttpClientHandlerTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandlerTest_AutoRedirect : HttpClientHandlerTest_AutoRedirect
{
public PlatformHandlerTest_AutoRedirect(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_DefaultCredentialsTest : DefaultCredentialsTest
{
public PlatformHandler_DefaultCredentialsTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_IdnaProtocolTests : IdnaProtocolTests
{
public PlatformHandler_IdnaProtocolTests(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
// WinHttp on Win7 does not support IDNA
protected override bool SupportsIdna => !PlatformDetection.IsWindows7;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpRetryProtocolTests : HttpRetryProtocolTests
{
public PlatformHandler_HttpRetryProtocolTests(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandlerTest_Cookies : HttpClientHandlerTest_Cookies
{
public PlatformHandlerTest_Cookies(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandlerTest_Cookies_Http11 : HttpClientHandlerTest_Cookies_Http11
{
public PlatformHandlerTest_Cookies_Http11(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_MaxResponseHeadersLength_Test : HttpClientHandler_MaxResponseHeadersLength_Test
{
public PlatformHandler_HttpClientHandler_MaxResponseHeadersLength_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_Cancellation_Test : HttpClientHandler_Cancellation_Test
{
public PlatformHandler_HttpClientHandler_Cancellation_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandler_HttpClientHandler_Authentication_Test : HttpClientHandler_Authentication_Test
{
public PlatformHandler_HttpClientHandler_Authentication_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => false;
}
// Enable this to run HTTP2 tests on platform handler
#if PLATFORM_HANDLER_HTTP2_TESTS
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
public sealed class PlatformHandlerTest_Http2 : HttpClientHandlerTest_Http2
{
- protected override bool UseSocketsHttpHandler => false;
}
// Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
+ [ActiveIssue(339)]
[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.SupportsAlpn))]
public sealed class PlatformHandlerTest_Cookies_Http2 : HttpClientHandlerTest_Cookies
{
- protected override bool UseSocketsHttpHandler => false;
protected override bool UseHttp2LoopbackServer => true;
}
#endif
-}
+}
\ No newline at end of file
[Theory, MemberData(nameof(RemoteServersMemberData))]
public async Task PostNonRewindableContentUsingAuth_PreAuthenticate_Success(Configuration.Http.RemoteServer remoteServer)
{
- if (IsWinHttpHandler)
- {
- // Issue #9228
- return;
- }
-
HttpContent content = new StreamContent(new CustomContent.CustomStream(Encoding.UTF8.GetBytes(ExpectedContent), false));
var credential = new NetworkCredential(UserName, Password);
await PostUsingAuthHelper(remoteServer, ExpectedContent, content, credential, preAuthenticate: true);
[Fact]
public void Authentication_UseStreamContent_Throws()
{
- RemoteExecutor.Invoke(async (useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(async (useHttp2String) =>
{
// This test validates the current limitation of CoreFx's NetFxToWinRtStreamAdapter
// which throws exceptions when trying to rewind a .NET Stream when it needs to be
string username = "testuser";
string password = "password";
Uri uri = Configuration.Http.RemoteHttp11Server.BasicAuthUriForCreds(userName: username, password: password);
- HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String);
+ HttpClientHandler handler = CreateHttpClientHandler(useHttp2String);
handler.Credentials = new NetworkCredential(username, password);
using (HttpClient client = CreateHttpClient(handler, useHttp2String))
await Assert.ThrowsAsync<HttpRequestException>(() => client.PostAsync(uri, content));
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[Fact]
public void Authentication_UseMultiInterfaceNonRewindableStreamContent_Throws()
{
- RemoteExecutor.Invoke(async (useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(async (useHttp2String) =>
{
string username = "testuser";
string password = "password";
Uri uri = Configuration.Http.RemoteHttp11Server.BasicAuthUriForCreds(userName: username, password: password);
- HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String);
+ HttpClientHandler handler = CreateHttpClientHandler(useHttp2String);
handler.Credentials = new NetworkCredential(username, password);
using (HttpClient client = CreateHttpClient(handler, useHttp2String))
await Assert.ThrowsAsync<HttpRequestException>(() => client.PostAsync(uri, content));
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[Fact]
public void Authentication_UseMultiInterfaceStreamContent_Success()
{
- RemoteExecutor.Invoke(async (useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(async (useHttp2String) =>
{
string username = "testuser";
string password = "password";
Uri uri = Configuration.Http.RemoteHttp11Server.BasicAuthUriForCreds(userName: username, password: password);
- HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String);
+ HttpClientHandler handler = CreateHttpClientHandler(useHttp2String);
handler.Credentials = new NetworkCredential(username, password);
using (HttpClient client = CreateHttpClient(handler, useHttp2String))
string responseContent = await response.Content.ReadAsStringAsync();
}
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[Fact]
public void Authentication_UseMemoryStreamVisibleBufferContent_Success()
{
- RemoteExecutor.Invoke(async (useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(async (useHttp2String) =>
{
string username = "testuser";
string password = "password";
Uri uri = Configuration.Http.RemoteHttp11Server.BasicAuthUriForCreds(userName: username, password: password);
- HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String);
+ HttpClientHandler handler = CreateHttpClientHandler(useHttp2String);
handler.Credentials = new NetworkCredential(username, password);
using (HttpClient client = CreateHttpClient(handler, useHttp2String))
string responseContent = await response.Content.ReadAsStringAsync();
}
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
[Fact]
public void Authentication_UseMemoryStreamNotVisibleBufferContent_Success()
{
- RemoteExecutor.Invoke(async (useSocketsHttpHandlerString, useHttp2String) =>
+ RemoteExecutor.Invoke(async (useHttp2String) =>
{
string username = "testuser";
string password = "password";
Uri uri = Configuration.Http.RemoteHttp11Server.BasicAuthUriForCreds(userName: username, password: password);
- HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String);
+ HttpClientHandler handler = CreateHttpClientHandler(useHttp2String);
handler.Credentials = new NetworkCredential(username, password);
using (HttpClient client = CreateHttpClient(handler, useHttp2String))
string responseContent = await response.Content.ReadAsStringAsync();
}
}
- }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
+ }, UseHttp2.ToString()).Dispose();
}
}
}
// Verify that the task completed.
Assert.True(((IAsyncResult)task).AsyncWaitHandle.WaitOne(new TimeSpan(0, 5, 0)));
Assert.True(task.IsCompleted, "Task was not yet completed");
-
- // Verify that the task completed successfully or is canceled.
- if (IsWinHttpHandler)
+
+ if (task.IsFaulted)
{
- // With WinHttpHandler, we may fault because canceling the task destroys the request handle
- // which may randomly cause an ObjectDisposedException (or other exception).
- Assert.True(
- task.Status == TaskStatus.RanToCompletion ||
- task.Status == TaskStatus.Canceled ||
- task.Status == TaskStatus.Faulted);
+ // Propagate exception for debugging
+ task.GetAwaiter().GetResult();
}
- else
- {
- if (task.IsFaulted)
- {
- // Propagate exception for debugging
- task.GetAwaiter().GetResult();
- }
- Assert.True(
- task.Status == TaskStatus.RanToCompletion ||
- task.Status == TaskStatus.Canceled);
- }
+ Assert.True(
+ task.Status == TaskStatus.RanToCompletion ||
+ task.Status == TaskStatus.Canceled);
}
}
{
public sealed class SocketsHttpHandler_HttpClientHandler_Asynchrony_Test : HttpClientHandler_Asynchrony_Test
{
- protected override bool UseSocketsHttpHandler => true;
-
public SocketsHttpHandler_HttpClientHandler_Asynchrony_Test(ITestOutputHelper output) : base(output) { }
[OuterLoop("Relies on finalization")]
public sealed class SocketsHttpHandler_HttpProtocolTests : HttpProtocolTests
{
- protected override bool UseSocketsHttpHandler => true;
-
public SocketsHttpHandler_HttpProtocolTests(ITestOutputHelper output) : base(output) { }
[Theory]
public sealed class SocketsHttpHandler_HttpProtocolTests_Dribble : HttpProtocolTests_Dribble
{
public SocketsHttpHandler_HttpProtocolTests_Dribble(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_DiagnosticsTest : DiagnosticsTest
{
public SocketsHttpHandler_DiagnosticsTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClient_SelectedSites_Test : HttpClient_SelectedSites_Test
{
public SocketsHttpHandler_HttpClient_SelectedSites_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientEKUTest : HttpClientEKUTest
{
public SocketsHttpHandler_HttpClientEKUTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_Decompression_Tests : HttpClientHandler_Decompression_Test
{
public SocketsHttpHandler_HttpClientHandler_Decompression_Tests(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test : HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test
{
public SocketsHttpHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_ClientCertificates_Test : HttpClientHandler_ClientCertificates_Test
{
public SocketsHttpHandler_HttpClientHandler_ClientCertificates_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_DefaultProxyCredentials_Test : HttpClientHandler_DefaultProxyCredentials_Test
{
public SocketsHttpHandler_HttpClientHandler_DefaultProxyCredentials_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_Finalization_Http11_Test : HttpClientHandler_Finalization_Test
{
public SocketsHttpHandler_HttpClientHandler_Finalization_Http11_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_Finalization_Http2_Test : HttpClientHandler_Finalization_Test
{
public SocketsHttpHandler_HttpClientHandler_Finalization_Http2_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
protected override bool UseHttp2 => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_MaxConnectionsPerServer_Test : HttpClientHandler_MaxConnectionsPerServer_Test
{
- protected override bool UseSocketsHttpHandler => true;
-
public SocketsHttpHandler_HttpClientHandler_MaxConnectionsPerServer_Test(ITestOutputHelper output) : base(output) { }
[OuterLoop("Incurs a small delay")]
public sealed class SocketsHttpHandler_HttpClientHandler_ServerCertificates_Test : HttpClientHandler_ServerCertificates_Test
{
public SocketsHttpHandler_HttpClientHandler_ServerCertificates_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_ResponseDrain_Test : HttpClientHandler_ResponseDrain_Test
{
- protected override bool UseSocketsHttpHandler => true;
-
protected override void SetResponseDrainTimeout(HttpClientHandler handler, TimeSpan time)
{
SocketsHttpHandler s = (SocketsHttpHandler)GetUnderlyingSocketsHttpHandler(handler);
public sealed class SocketsHttpHandler_PostScenarioTest : PostScenarioTest
{
public SocketsHttpHandler_PostScenarioTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
[Theory]
[InlineData(false)]
public sealed class SocketsHttpHandler_ResponseStreamTest : ResponseStreamTest
{
public SocketsHttpHandler_ResponseStreamTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_SslProtocols_Test : HttpClientHandler_SslProtocols_Test
{
public SocketsHttpHandler_HttpClientHandler_SslProtocols_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_Proxy_Test : HttpClientHandler_Proxy_Test
{
public SocketsHttpHandler_HttpClientHandler_Proxy_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public abstract class SocketsHttpHandler_TrailingHeaders_Test : HttpClientHandlerTestBase
public class SocketsHttpHandler_Http1_TrailingHeaders_Test : SocketsHttpHandler_TrailingHeaders_Test
{
public SocketsHttpHandler_Http1_TrailingHeaders_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
[Theory]
[InlineData(false)]
public sealed class SocketsHttpHandler_Http2_TrailingHeaders_Test : SocketsHttpHandler_TrailingHeaders_Test
{
public SocketsHttpHandler_Http2_TrailingHeaders_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
protected override bool UseHttp2 => true;
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.SupportsAlpn))]
public sealed class SocketsHttpHandler_SchSendAuxRecordHttpTest : SchSendAuxRecordHttpTest
{
public SocketsHttpHandler_SchSendAuxRecordHttpTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandlerTest : HttpClientHandlerTest
{
public SocketsHttpHandler_HttpClientHandlerTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandlerTest_AutoRedirect : HttpClientHandlerTest_AutoRedirect
{
public SocketsHttpHandlerTest_AutoRedirect(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_DefaultCredentialsTest : DefaultCredentialsTest
{
public SocketsHttpHandler_DefaultCredentialsTest(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_IdnaProtocolTests : IdnaProtocolTests
{
public SocketsHttpHandler_IdnaProtocolTests(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
protected override bool SupportsIdna => true;
}
public sealed class SocketsHttpHandler_HttpRetryProtocolTests : HttpRetryProtocolTests
{
public SocketsHttpHandler_HttpRetryProtocolTests(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandlerTest_Cookies : HttpClientHandlerTest_Cookies
{
public SocketsHttpHandlerTest_Cookies(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandlerTest_Cookies_Http11 : HttpClientHandlerTest_Cookies_Http11
{
public SocketsHttpHandlerTest_Cookies_Http11(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_Cancellation_Test : HttpClientHandler_Cancellation_Test
{
public SocketsHttpHandler_HttpClientHandler_Cancellation_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
[Fact]
public void ConnectTimeout_Default()
public sealed class SocketsHttpHandler_HttpClientHandler_MaxResponseHeadersLength_Test : HttpClientHandler_MaxResponseHeadersLength_Test
{
public SocketsHttpHandler_HttpClientHandler_MaxResponseHeadersLength_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_Authentication_Test : HttpClientHandler_Authentication_Test
{
public SocketsHttpHandler_HttpClientHandler_Authentication_Test(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
[Theory]
[MemberData(nameof(Authentication_SocketsHttpHandler_TestData))]
public sealed class SocketsHttpHandler_ConnectionUpgrade_Test : HttpClientHandlerTestBase
{
- protected override bool UseSocketsHttpHandler => true;
-
public SocketsHttpHandler_ConnectionUpgrade_Test(ITestOutputHelper output) : base(output) { }
[Fact]
public sealed class SocketsHttpHandler_Connect_Test : HttpClientHandlerTestBase
{
- protected override bool UseSocketsHttpHandler => true;
-
public SocketsHttpHandler_Connect_Test(ITestOutputHelper output) : base(output) { }
[Fact]
public sealed class SocketsHttpHandler_HttpClientHandler_ConnectionPooling_Test : HttpClientHandlerTestBase
{
- protected override bool UseSocketsHttpHandler => true;
-
public SocketsHttpHandler_HttpClientHandler_ConnectionPooling_Test(ITestOutputHelper output) : base(output) { }
[Fact]
{
await Http2LoopbackServerFactory.CreateServerAsync(async (server, url) =>
{
- HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandler : true, useHttp2LoopbackServer : true);
+ HttpClientHandler handler = CreateHttpClientHandler(useHttp2LoopbackServer : true);
SocketsHttpHandler s = (SocketsHttpHandler)GetUnderlyingSocketsHttpHandler(handler);
switch (timeoutPropertyName)
{
}
}
- // Test only WinHttpHandler since the CurlHandler was removed
- [PlatformSpecific(TestPlatforms.Windows)]
- public sealed class SocketsHttpHandler_ExternalConfiguration_Test : HttpClientHandlerTestBase
- {
- public SocketsHttpHandler_ExternalConfiguration_Test(ITestOutputHelper output) : base(output) { }
-
- private const string EnvironmentVariableSettingName = "DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER";
- private const string AppContextSettingName = "System.Net.Http.UseSocketsHttpHandler";
-
- private static bool UseSocketsHttpHandlerEnvironmentVariableIsNotSet =>
- string.IsNullOrEmpty(Environment.GetEnvironmentVariable(EnvironmentVariableSettingName));
-
- [ConditionalTheory(nameof(UseSocketsHttpHandlerEnvironmentVariableIsNotSet))]
- [InlineData("true", true)]
- [InlineData("TRUE", true)]
- [InlineData("tRuE", true)]
- [InlineData("1", true)]
- [InlineData("0", false)]
- [InlineData("false", false)]
- [InlineData("helloworld", true)]
- [InlineData("", true)]
- public void HttpClientHandler_SettingEnvironmentVariableChangesDefault(string envVarValue, bool expectedUseSocketsHandler)
- {
- RemoteExecutor.Invoke((innerEnvVarValue, innerExpectedUseSocketsHandler) =>
- {
- Environment.SetEnvironmentVariable(EnvironmentVariableSettingName, innerEnvVarValue);
- using (var handler = new HttpClientHandler())
- {
- Assert.Equal(bool.Parse(innerExpectedUseSocketsHandler), IsSocketsHttpHandler(handler));
- }
- }, envVarValue, expectedUseSocketsHandler.ToString()).Dispose();
- }
-
- [Fact]
- public void HttpClientHandler_SettingAppContextChangesDefault()
- {
- RemoteExecutor.Invoke(() =>
- {
- AppContext.SetSwitch(AppContextSettingName, isEnabled: true);
- using (var handler = new HttpClientHandler())
- {
- Assert.True(IsSocketsHttpHandler(handler));
- }
-
- AppContext.SetSwitch(AppContextSettingName, isEnabled: false);
- using (var handler = new HttpClientHandler())
- {
- Assert.False(IsSocketsHttpHandler(handler));
- }
- }).Dispose();
- }
-
- [Fact]
- public void HttpClientHandler_AppContextOverridesEnvironmentVariable()
- {
- RemoteExecutor.Invoke(() =>
- {
- Environment.SetEnvironmentVariable(EnvironmentVariableSettingName, "true");
- using (var handler = new HttpClientHandler())
- {
- Assert.True(IsSocketsHttpHandler(handler));
- }
-
- AppContext.SetSwitch(AppContextSettingName, isEnabled: false);
- using (var handler = new HttpClientHandler())
- {
- Assert.False(IsSocketsHttpHandler(handler));
- }
-
- AppContext.SetSwitch(AppContextSettingName, isEnabled: true);
- Environment.SetEnvironmentVariable(EnvironmentVariableSettingName, null);
- using (var handler = new HttpClientHandler())
- {
- Assert.True(IsSocketsHttpHandler(handler));
- }
- }).Dispose();
- }
- }
-
public sealed class SocketsHttpHandlerTest_LocationHeader
{
private static readonly byte[] s_redirectResponseBefore = Encoding.ASCII.GetBytes(
public sealed class SocketsHttpHandlerTest_Http2 : HttpClientHandlerTest_Http2
{
public SocketsHttpHandlerTest_Http2(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.SupportsAlpn))]
public sealed class SocketsHttpHandlerTest_Cookies_Http2 : HttpClientHandlerTest_Cookies
{
public SocketsHttpHandlerTest_Cookies_Http2(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
protected override bool UseHttp2 => true;
}
public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Http2 : HttpClientHandlerTest
{
public SocketsHttpHandlerTest_HttpClientHandlerTest_Http2(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
protected override bool UseHttp2 => true;
}
public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http11 : HttpClientHandlerTest_Headers
{
public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http11(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
}
[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.SupportsAlpn))]
public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http2 : HttpClientHandlerTest_Headers
{
public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http2(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
protected override bool UseHttp2 => true;
}
public sealed class SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http2 : HttpClientHandler_Cancellation_Test
{
public SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http2(ITestOutputHelper output) : base(output) { }
- protected override bool UseSocketsHttpHandler => true;
protected override bool UseHttp2 => true;
}
}
<Compile Include="..\..\..\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinHttpException.cs">
<Link>ProductionCode\System\Net\Http\WinHttpException.cs</Link>
</Compile>
- <Compile Include="..\..\..\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinInetProxyHelper.cs">
- <Link>ProductionCode\System\Net\Http\WinInetProxyHelper.cs</Link>
- </Compile>
<Compile Include="..\..\..\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinHttpTraceHelper.cs">
<Link>ProductionCode\System\Net\Http\WinHttpTraceHelper.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Windows\WinHttp\Interop.winhttp_types.cs">
<Link>ProductionCode\Common\Interop\Windows\WinHttp\Interop.winhttp_types.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)System\Net\Http\WinInetProxyHelper.cs">
+ <Link>Common\System\Net\Http\WinInetProxyHelper.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)System\Net\Http\Http2\IHttpHeadersHandler.cs">
<Link>Common\System\Net\Http\Http2\IHttpHeadersHandler.cs</Link>
</Compile>