Skip to content

Commit

Permalink
Fix HttpClient configuration not being forwarded to Flux
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyDurov committed Apr 22, 2024
1 parent 6603e54 commit 4128924
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/BitzArt.Flux.REST/Extensions/UsingRestExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public static IFluxRestServiceBuilder UsingRest(this IFluxServicePreBuilder preb
builder.Factory.ServiceContexts.Add(fluxServiceProvider);

// If configuration action is null, do nothing
var httpClientConfiguration = builder.HttpClientConfiguration;
httpClientConfiguration ??= (_, _) => { };
builder.HttpClientConfiguration ??= (_, _) => { };

builder.Services.AddHttpClient(fluxServiceProvider.ServiceName, httpClientConfiguration);
builder.Services.AddHttpClient(fluxServiceProvider.ServiceName, (serviceProvider, httpClient) =>
{
builder.HttpClientConfiguration(serviceProvider, httpClient);
});

builder.Services.AddScoped<IFluxServiceContext>(x =>
{
Expand Down
3 changes: 2 additions & 1 deletion tests/BitzArt.Flux.REST.Tests/ServiceRegistrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public void UsingRest_ConfigureHttpClient_ConfiguresHttpClient()
Assert.NotNull(setContext);

var setContextCasted = (FluxRestSetContext<TestModel, int>)setContext;
var httpClient = setContextCasted.HttpClient;

Assert.Contains(setContextCasted.HttpClient.DefaultRequestHeaders,
Assert.Contains(httpClient.DefaultRequestHeaders,
x => x.Key == testHeader.Key && x.Value.Single() == testHeader.Value);
}

Expand Down

0 comments on commit 4128924

Please sign in to comment.