Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Add parameter to factory method for setting handler options #246

Merged
merged 9 commits into from
May 21, 2024
35 changes: 28 additions & 7 deletions src/KiotaClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware;
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware.Options;
Expand All @@ -32,17 +33,37 @@ public static HttpClient Create(HttpMessageHandler? finalHandler = null)
/// Creates a default set of middleware to be used by the <see cref="HttpClient"/>.
/// </summary>
/// <returns>A list of the default handlers used by the client.</returns>
public static IList<DelegatingHandler> CreateDefaultHandlers()
public static IList<DelegatingHandler> CreateDefaultHandlers(IRequestOption[]? optionsForHandlers = null)
baywet marked this conversation as resolved.
Show resolved Hide resolved
{
optionsForHandlers ??= [];

return new List<DelegatingHandler>
{
//add the default middlewares as they are ready
baywet marked this conversation as resolved.
Show resolved Hide resolved
new UriReplacementHandler<UriReplacementHandlerOption>(),
new RetryHandler(),
new RedirectHandler(),
new ParametersNameDecodingHandler(),
new UserAgentHandler(),
new HeadersInspectionHandler(),

optionsForHandlers.OfType<UriReplacementHandlerOption>().FirstOrDefault() is UriReplacementHandlerOption uriReplacementOption
? new UriReplacementHandler<UriReplacementHandlerOption>(uriReplacementOption)
: new UriReplacementHandler<UriReplacementHandlerOption>(),

optionsForHandlers.OfType<RetryHandlerOption>().FirstOrDefault() is RetryHandlerOption retryHandlerOption
? new RetryHandler(retryHandlerOption)
: new RetryHandler(),

optionsForHandlers.OfType<RedirectHandlerOption>().FirstOrDefault() is RedirectHandlerOption redirectHandlerOption
? new RedirectHandler(redirectHandlerOption)
: new RedirectHandler(),

optionsForHandlers.OfType<ParametersNameDecodingOption>().FirstOrDefault() is ParametersNameDecodingOption parametersNameDecodingOption
? new ParametersNameDecodingHandler(parametersNameDecodingOption)
: new ParametersNameDecodingHandler(),

optionsForHandlers.OfType<UserAgentHandlerOption>().FirstOrDefault() is UserAgentHandlerOption userAgentHandlerOption
? new UserAgentHandler(userAgentHandlerOption)
: new UserAgentHandler(),

optionsForHandlers.OfType<HeadersInspectionHandlerOption>().FirstOrDefault() is HeadersInspectionHandlerOption headersInspectionHandlerOption
? new HeadersInspectionHandler(headersInspectionHandlerOption)
: new HeadersInspectionHandler(),
};
}
/// <summary>
Expand Down