Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HttpClient registration for WebhookSender #1758

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading