Skip to content

Commit 039fe54

Browse files
fix(ConfigurableMessageHandler): Only validate headers on first attempt.
1 parent e02d17a commit 039fe54

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Src/Support/Google.Apis.Auth/OAuth2/AccessTokenWithHeaders.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
using Google.Apis.Util;
1818
using System.Collections.Generic;
1919
using System.Collections.ObjectModel;
20+
using System.Linq;
2021
using System.Net.Http;
2122
using System.Net.Http.Headers;
2223

@@ -78,12 +79,14 @@ public void AddHeaders(HttpRequestHeaders requestHeaders)
7879

7980
foreach (var header in Headers)
8081
{
82+
// Overwite any pre-existing header with the provided values.
83+
requestHeaders.Remove(header.Key);
8184
requestHeaders.Add(header.Key, header.Value);
8285
}
8386
}
8487

8588
/// <summary>
86-
/// Adds the headers in this object to the given request.
89+
/// Adds the headers in this object to the given request. Overwriting any already present header fields.
8790
/// </summary>
8891
/// <param name="request">The request to add the headers to.</param>
8992
public void AddHeaders(HttpRequestMessage request) =>

Src/Support/Google.Apis.Core/Http/ConfigurableMessageHandler.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,12 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
466466

467467
// Before having the credential intercept the call, check that quota project hasn't
468468
// been added as a header. Quota project cannot be added except through the credential.
469-
CheckValidAfterInterceptors(request);
469+
// We only perform this check on the first attempt; on retries the header may be
470+
// present from a previous attempt.
471+
if (triesRemaining == maxRetries) // This is the first attempt
472+
{
473+
CheckValidAfterInterceptors(request);
474+
}
470475

471476
await CredentialInterceptAsync(request, cancellationToken).ConfigureAwait(false);
472477

0 commit comments

Comments
 (0)