Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extract AuthenticationHelper class to a separate file for tvOS;
  • Loading branch information
MaximLipnin committed Jul 8, 2021
commit bde0bf9c36504988fb2ce86b4670122329c4fd20
3 changes: 2 additions & 1 deletion src/libraries/System.Net.Http/src/System.Net.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<Compile Include="System\Net\Http\Headers\KnownHeader.Http2And3.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\AuthenticationHelper.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\AuthenticationHelper.Digest.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\AuthenticationHelper.NtAuth.cs" />
<Compile Condition="'$(TargetstvOS)' != 'true'" Include="System\Net\Http\SocketsHttpHandler\AuthenticationHelper.NtAuth.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\ChunkedEncodingReadStream.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\ChunkedEncodingWriteStream.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\ConnectHelper.cs" />
Expand Down Expand Up @@ -348,6 +348,7 @@
Link="Common\System\Net\Security\NegotiateStreamPal.Unix.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetstvOS)' == 'true'">
<Compile Include="System\Net\Http\SocketsHttpHandler\AuthenticationHelper.NtAuth.tvOS.cs" />
<Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\GssSafeHandles.PlatformNotSupported.cs"
Link="Common\Microsoft\Win32\SafeHandles\GssSafeHandles.PlatformNotSupported.cs" />
<Compile Include="$(CommonPath)System\Net\Security\NegotiateStreamPal.PlatformNotSupported.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
using System.Diagnostics;
using System.Net;
using System.Net.Http.Headers;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using System.Security.Authentication.ExtendedProtection;

namespace System.Net.Http
{
[UnsupportedOSPlatform("tvos")]
internal static partial class AuthenticationHelper
{
private static Task<HttpResponseMessage> InnerSendAsync(HttpRequestMessage request, bool async, bool isProxyAuth, HttpConnectionPool pool, HttpConnection connection, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

namespace System.Net.Http
{
internal static partial class AuthenticationHelper
{
private static Task<HttpResponseMessage> InnerSendAsync(HttpRequestMessage request, Uri authUri, bool async, ICredentials credentials, bool isProxyAuth, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken)
{
return isProxyAuth ?
SendWithProxyAuthAsync(request, authUri, async, credentials, true, connectionPool, cancellationToken).AsTask() :
SendWithRequestAuthAsync(request, async, credentials, true, connectionPool, cancellationToken).AsTask();
}

public static Task<HttpResponseMessage> SendWithNtProxyAuthAsync(HttpRequestMessage request, Uri proxyUri, bool async, ICredentials proxyCredentials, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken)
{
return InnerSendAsync(request, proxyUri, async, proxyCredentials, isProxyAuth: true, connection, connectionPool, cancellationToken);
}

public static Task<HttpResponseMessage> SendWithNtConnectionAuthAsync(HttpRequestMessage request, bool async, ICredentials credentials, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken)
{
Debug.Assert(request.RequestUri != null);
return InnerSendAsync(request, request.RequestUri, async, credentials, isProxyAuth: false, connection, connectionPool, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -16,7 +15,6 @@ public HttpAuthenticatedConnectionHandler(HttpConnectionPoolManager poolManager)
_poolManager = poolManager;
}

[UnsupportedOSPlatform("tvos")]
internal override ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
{
return _poolManager.SendAsync(request, async, doRequestAuth: true, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -377,7 +376,6 @@ private Task WriteHexInt32Async(int value, bool async)
return WriteAsciiStringAsync(value.ToString("X", CultureInfo.InvariantCulture), async);
}

[UnsupportedOSPlatform("tvos")]
public async Task<HttpResponseMessage> SendAsyncCore(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
{
TaskCompletionSource<bool>? allowExpect100ToContinue = null;
Expand Down Expand Up @@ -804,7 +802,6 @@ public async Task<HttpResponseMessage> SendAsyncCore(HttpRequestMessage request,
}
}

[UnsupportedOSPlatform("tvos")]
public sealed override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken) =>
SendAsyncCore(request, async, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -16,7 +15,6 @@ public HttpConnectionHandler(HttpConnectionPoolManager poolManager)
_poolManager = poolManager;
}

[UnsupportedOSPlatform("tvos")]
internal override ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
{
return _poolManager.SendAsync(request, async, doRequestAuth: false, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ private static HttpRequestException GetVersionException(HttpRequestMessage reque
}

// Returns null if HTTP2 cannot be used
[UnsupportedOSPlatform("tvos")]
private async ValueTask<Http2Connection?> GetHttp2ConnectionAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
{
Debug.Assert(_kind == HttpConnectionKind.Https || _kind == HttpConnectionKind.SslProxyTunnel || _kind == HttpConnectionKind.Http || _kind == HttpConnectionKind.SocksTunnel || _kind == HttpConnectionKind.SslSocksTunnel);
Expand Down Expand Up @@ -813,7 +812,6 @@ private async ValueTask<Http3Connection> GetHttp3ConnectionAsync(HttpRequestMess
}

// Returns null if HTTP2 cannot be used.
[UnsupportedOSPlatform("tvos")]
private async ValueTask<HttpResponseMessage?> TrySendUsingHttp2Async(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
{
// Send using HTTP/2 if we can.
Expand All @@ -834,7 +832,6 @@ private async ValueTask<Http3Connection> GetHttp3ConnectionAsync(HttpRequestMess
return null;
}

[UnsupportedOSPlatform("tvos")]
private async ValueTask<HttpResponseMessage> SendUsingHttp11Async(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
{
HttpConnection? connection = await GetOrReserveHttp11ConnectionAsync(async, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -865,7 +862,6 @@ private async ValueTask<HttpResponseMessage> SendUsingHttp11Async(HttpRequestMes
}
}

[UnsupportedOSPlatform("tvos")]
private async ValueTask<HttpResponseMessage> DetermineVersionAndSendAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
{
HttpResponseMessage? response;
Expand Down Expand Up @@ -900,7 +896,6 @@ private async ValueTask<HttpResponseMessage> DetermineVersionAndSendAsync(HttpRe
return await SendUsingHttp11Async(request, async, doRequestAuth, cancellationToken).ConfigureAwait(false);
}

[UnsupportedOSPlatform("tvos")]
private async ValueTask<HttpResponseMessage> SendAndProcessAltSvcAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
{
HttpResponseMessage response = await DetermineVersionAndSendAsync(request, async, doRequestAuth, cancellationToken).ConfigureAwait(false);
Expand All @@ -914,7 +909,6 @@ private async ValueTask<HttpResponseMessage> SendAndProcessAltSvcAsync(HttpReque
return response;
}

[UnsupportedOSPlatform("tvos")]
public async ValueTask<HttpResponseMessage> SendWithRetryAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
{
int retryCount = 0;
Expand Down Expand Up @@ -1202,7 +1196,6 @@ public void OnNetworkChanged()
}
}

[UnsupportedOSPlatform("tvos")]
public Task<HttpResponseMessage> SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
{
if (doRequestAuth && Settings._credentials != null)
Expand All @@ -1215,7 +1208,6 @@ public Task<HttpResponseMessage> SendWithNtConnectionAuthAsync(HttpConnection co

private bool DoProxyAuth => (_kind == HttpConnectionKind.Proxy || _kind == HttpConnectionKind.ProxyConnect);

[UnsupportedOSPlatform("tvos")]
public Task<HttpResponseMessage> SendWithNtProxyAuthAsync(HttpConnection connection, HttpRequestMessage request, bool async, CancellationToken cancellationToken)
{
if (DoProxyAuth && ProxyCredentials is not null)
Expand All @@ -1226,7 +1218,6 @@ public Task<HttpResponseMessage> SendWithNtProxyAuthAsync(HttpConnection connect
return connection.SendAsync(request, async, cancellationToken);
}

[UnsupportedOSPlatform("tvos")]
public ValueTask<HttpResponseMessage> SendWithProxyAuthAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
{
if (DoProxyAuth && ProxyCredentials is not null)
Expand All @@ -1237,7 +1228,6 @@ public ValueTask<HttpResponseMessage> SendWithProxyAuthAsync(HttpRequestMessage
return SendWithRetryAsync(request, async, doRequestAuth, cancellationToken);
}

[UnsupportedOSPlatform("tvos")]
public ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
{
if (doRequestAuth && Settings._credentials != null)
Expand All @@ -1248,7 +1238,6 @@ public ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool
return SendWithProxyAuthAsync(request, async, doRequestAuth, cancellationToken);
}

[UnsupportedOSPlatform("tvos")]
private async ValueTask<(Socket?, Stream, TransportContext?)> ConnectAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
{
// If a non-infinite connect timeout has been set, create and use a new CancellationToken that will be canceled
Expand Down Expand Up @@ -1369,7 +1358,6 @@ public ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool
}
}

[UnsupportedOSPlatform("tvos")]
internal async ValueTask<HttpConnection> CreateHttp11ConnectionAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
{
(Socket? socket, Stream? stream, TransportContext? transportContext) =
Expand Down Expand Up @@ -1464,7 +1452,6 @@ private async ValueTask<Http2Connection> ConstructHttp2ConnectionAsync(Stream st
return http2Connection;
}

[UnsupportedOSPlatform("tvos")]
private async ValueTask<Stream> EstablishProxyTunnelAsync(bool async, HttpRequestHeaders? headers, CancellationToken cancellationToken)
{
Debug.Assert(_originAuthority != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.ExceptionServices;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using System.Net.NetworkInformation;
Expand Down Expand Up @@ -327,7 +326,6 @@ private HttpConnectionKey GetConnectionKey(HttpRequestMessage request, Uri? prox
}
}

[UnsupportedOSPlatform("tvos")]
public ValueTask<HttpResponseMessage> SendAsyncCore(HttpRequestMessage request, Uri? proxyUri, bool async, bool doRequestAuth, bool isProxyConnect, CancellationToken cancellationToken)
{
HttpConnectionKey key = GetConnectionKey(request, proxyUri, isProxyConnect);
Expand Down Expand Up @@ -367,13 +365,11 @@ public ValueTask<HttpResponseMessage> SendAsyncCore(HttpRequestMessage request,
return pool.SendAsync(request, async, doRequestAuth, cancellationToken);
}

[UnsupportedOSPlatform("tvos")]
public ValueTask<HttpResponseMessage> SendProxyConnectAsync(HttpRequestMessage request, Uri proxyUri, bool async, CancellationToken cancellationToken)
{
return SendAsyncCore(request, proxyUri, async, doRequestAuth: false, isProxyConnect: true, cancellationToken);
}

[UnsupportedOSPlatform("tvos")]
public ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
{
if (_proxy == null)
Expand Down Expand Up @@ -427,7 +423,6 @@ public ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool
/// <param name="multiProxy">The set of proxies to use.</param>
/// <param name="firstProxy">The first proxy try.</param>
/// <param name="cancellationToken">The cancellation token to use for the operation.</param>
[UnsupportedOSPlatform("tvos")]
private async ValueTask<HttpResponseMessage> SendAsyncMultiProxy(HttpRequestMessage request, bool async, bool doRequestAuth, MultiProxy multiProxy, Uri? firstProxy, CancellationToken cancellationToken)
{
HttpRequestException rethrowException;
Expand Down