Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Omondi <[email protected]>
  • Loading branch information
Ndiritu and andrueastman authored Nov 5, 2024
1 parent d5882b3 commit ecd1232
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
12 changes: 1 addition & 11 deletions src/http/httpClient/KiotaClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,7 @@ public static HttpClient Create(BaseBearerTokenAuthenticationProvider authentica
{
var defaultHandlersEnumerable = CreateDefaultHandlers(optionsForHandlers);
defaultHandlersEnumerable.Add(new AuthorizationHandler(authenticationProvider));
int count = 0;
foreach(var _ in defaultHandlersEnumerable) count++;

var defaultHandlersArray = new DelegatingHandler[count];
int index = 0;
foreach(var handler2 in defaultHandlersEnumerable)
{
defaultHandlersArray[index++] = handler2;
}
var handler = ChainHandlersCollectionAndGetFirstLink(finalHandler ?? GetDefaultHttpMessageHandler(), defaultHandlersArray);
return handler != null ? new HttpClient(handler) : new HttpClient();
return Create(defaultHandlersEnumerable, finalHandler);
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions src/http/httpClient/Middleware/AuthorizationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class AuthorizationHandler : DelegatingHandler
/// <exception cref="ArgumentNullException"></exception>
public AuthorizationHandler(BaseBearerTokenAuthenticationProvider authenticationProvider)
{
if(authenticationProvider == null) throw new ArgumentNullException(nameof(authenticationProvider));
this.authenticationProvider = authenticationProvider;
this.authenticationProvider = authenticationProvider ?? throw new ArgumentNullException(nameof(authenticationProvider));
}

/// <summary>
Expand Down Expand Up @@ -73,7 +72,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
return response;
activity?.AddEvent(new ActivityEvent("com.microsoft.kiota.handler.authorization.challenge_received"));
additionalAuthenticationContext[ContinuousAccessEvaluation.ClaimsKey] = claims;
HttpRequestMessage retryRequest = response.RequestMessage;
var retryRequest = await response.RequestMessage.CloneAsync(cancellationToken);
await AuthenticateRequestAsync(retryRequest, additionalAuthenticationContext, cancellationToken, activity).ConfigureAwait(false);
activity?.SetTag("http.request.resend_count", 1);
return await base.SendAsync(retryRequest, cancellationToken).ConfigureAwait(false);
Expand Down

0 comments on commit ecd1232

Please sign in to comment.