Skip to content

Commit

Permalink
Fix HttpClient registration for WebhookSender
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Dec 19, 2024
1 parent d4bdd23 commit dcfd21c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public static IHostApplicationBuilder AddWebhookDeliveryService(this IHostApplic
{
AddWebhookOptions(builder);

builder.Services.AddSingleton<IWebhookSender, WebhookSender>();
WebhookSender.AddHttpClient(builder.Services);
WebhookSender.Register(builder.Services);

builder.Services.AddSingleton<IHostedService, WebhookDeliveryService>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task SendMessageAsync(WebhookMessage message, CancellationToken can
response.EnsureSuccessStatusCode();
}

public static void AddHttpClient(IServiceCollection services, Func<HttpMessageHandler>? getPrimaryHandler = null)
public static void Register(IServiceCollection services, Func<HttpMessageHandler>? getPrimaryHandler = null)
{
// We configure the options here manually rather than using the library-provided extension methods so that they don't 'bleed out' globally;
// it's feasible we could want a different configuration of, say, AddContentDigestOptions for use elsewhere.
Expand Down Expand Up @@ -108,8 +108,10 @@ IOptions<MessageSigningOptions> GetMessageSigningOptions(IServiceProvider servic
return new ECDsaP382Sha384SignatureProvider(cert, signingKeyId);
});

services.AddSingleton<IWebhookSender, WebhookSender>();

var httpClientBuilder = services
.AddHttpClient<WebhookSender>(client =>
.AddHttpClient<IWebhookSender, WebhookSender>(client =>
{
client.Timeout = TimeSpan.FromSeconds(TimeoutSeconds);
client.DefaultRequestHeaders.ExpectContinue = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ public WebhookReceiver()
];
});

builder.Services.AddSingleton<WebhookSender>();

builder.Services.AddSingleton<WebhookMessageRecorder>();
WebhookSender.AddHttpClient(builder.Services, () => _server!.CreateHandler());
WebhookSender.Register(builder.Services, () => _server!.CreateHandler());

builder.Services.Configure<RequestSignatureVerificationOptions>(options =>
{
Expand Down Expand Up @@ -206,7 +204,7 @@ public WebhookReceiver()

public WebhookMessageRecorder WebhookMessageRecorder => Services.GetRequiredService<WebhookMessageRecorder>();

public WebhookSender GetWebhookSender() => Services.GetRequiredService<WebhookSender>();
public IWebhookSender GetWebhookSender() => Services.GetRequiredService<IWebhookSender>();

public WebhookOptions GetWebhookOptions() => Services.GetRequiredService<IOptions<WebhookOptions>>().Value;

Expand Down

0 comments on commit dcfd21c

Please sign in to comment.