This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Handle NT auth with Connection: close on initial challenge #31527
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -464,7 +464,14 @@ public async Task<HttpResponseMessage> SendWithRetryAsync(HttpRequestMessage req | |
|
|
||
| try | ||
| { | ||
| return await connection.SendAsync(request, doRequestAuth, cancellationToken).ConfigureAwait(false); | ||
| if (connection is HttpConnection) | ||
| { | ||
| return await SendWithNtConnectionAuthAsync((HttpConnection)connection, request, doRequestAuth, cancellationToken).ConfigureAwait(false); | ||
| } | ||
| else | ||
| { | ||
| return await connection.SendAsync(request, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: FWIW, code gen would end up being a bit better if this were instead written to have a single await instead of two, e.g. Task<HttpResponseMessage> resp = connection is HttpConnection httpConnection ?
SendWithNtConnectionAuthAsync(httpConnection, request, doRequestAuth, cancellationToken) :
connection.SendAsync(request, cancellationToken);
return await resp.ConfigureAwait(false); |
||
| } | ||
| catch (HttpRequestException e) when (!isNewConnection && e.AllowRetry) | ||
| { | ||
|
|
@@ -478,6 +485,35 @@ public async Task<HttpResponseMessage> SendWithRetryAsync(HttpRequestMessage req | |
| } | ||
| } | ||
|
|
||
| public async Task<HttpResponseMessage> SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, bool doRequestAuth, CancellationToken cancellationToken) | ||
| { | ||
| connection.Acquire(); | ||
| try | ||
| { | ||
| if (doRequestAuth && Settings._credentials != null) | ||
| { | ||
| return await AuthenticationHelper.SendWithNtConnectionAuthAsync(request, Settings._credentials, connection, this, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| return await SendWithNtProxyAuthAsync(connection, request, cancellationToken).ConfigureAwait(false); | ||
| } | ||
| finally | ||
| { | ||
| connection.Release(); | ||
| } | ||
| } | ||
|
|
||
| public Task<HttpResponseMessage> SendWithNtProxyAuthAsync(HttpConnection connection, HttpRequestMessage request, CancellationToken cancellationToken) | ||
| { | ||
| if (AnyProxyKind && ProxyCredentials != null) | ||
| { | ||
| return AuthenticationHelper.SendWithNtProxyAuthAsync(request, ProxyUri, ProxyCredentials, connection, this, cancellationToken); | ||
| } | ||
|
|
||
| return connection.SendAsync(request, cancellationToken); | ||
| } | ||
|
|
||
|
|
||
| public Task<HttpResponseMessage> SendWithProxyAuthAsync(HttpRequestMessage request, bool doRequestAuth, CancellationToken cancellationToken) | ||
| { | ||
| if ((_kind == HttpConnectionKind.Proxy || _kind == HttpConnectionKind.ProxyConnect) && | ||
|
|
@@ -556,7 +592,7 @@ public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool doRe | |
| } | ||
| } | ||
|
|
||
| private async ValueTask<(HttpConnection, HttpResponseMessage)> CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
| internal async ValueTask<(HttpConnection, HttpResponseMessage)> CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
| { | ||
| (Socket socket, Stream stream, TransportContext transportContext, HttpResponseMessage failureResponse) = | ||
| await ConnectAsync(request, false, cancellationToken).ConfigureAwait(false); | ||
|
|
@@ -706,6 +742,15 @@ private void IncrementConnectionCountNoLock() | |
| _associatedConnectionCount++; | ||
| } | ||
|
|
||
| internal void IncrementConnectionCount() | ||
| { | ||
| lock (SyncObj) | ||
| { | ||
| IncrementConnectionCountNoLock(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Decrements the number of connections associated with the pool. | ||
| /// If there are waiters on the pool due to having reached the maximum, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Assert that connection is null? If the logic in CreateHttp11ConnectionAsync changes such that both connection and response could be non-null, then the connection pool's count tracking will end up being incorrect.