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

Commit

Permalink
Make UriReplacementHandler's constructor option optional and make it …
Browse files Browse the repository at this point in the history
…respect request options
  • Loading branch information
NetherGranite committed Apr 20, 2024
1 parent daaaebd commit b295919
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Middleware/UriReplacementHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@ namespace Microsoft.Kiota.Http.HttpClientLibrary.Middleware;
/// <typeparam name="TUriReplacementHandlerOption">A type with the rules used to perform a URI replacement.</typeparam>
public class UriReplacementHandler<TUriReplacementHandlerOption> : DelegatingHandler where TUriReplacementHandlerOption : IUriReplacementHandlerOption
{
private readonly TUriReplacementHandlerOption uriReplacement;
private readonly TUriReplacementHandlerOption? _uriReplacement;

/// <summary>
/// Creates a new UriReplacementHandler.
/// </summary>
/// <param name="uriReplacement">An object with the URI replacement rules.</param>
public UriReplacementHandler(TUriReplacementHandlerOption uriReplacement)
public UriReplacementHandler(TUriReplacementHandlerOption? uriReplacement = default)
{
this.uriReplacement = uriReplacement;
this._uriReplacement = uriReplacement;
}

/// <inheritdoc/>
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
var uriReplacement = request.GetRequestOption<TUriReplacementHandlerOption>() ?? _uriReplacement;

// If there is no URI replacement to apply, then just skip this handler.
if(uriReplacement is null)
{
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
}

Activity? activity;
if(request.GetRequestOption<ObservabilityOptions>() is { } obsOptions)
{
Expand Down

0 comments on commit b295919

Please sign in to comment.