File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ limitations under the License.
1717using Google . Apis . Util ;
1818using System . Collections . Generic ;
1919using System . Collections . ObjectModel ;
20+ using System . Linq ;
2021using System . Net . Http ;
2122using 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 ) =>
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments