I've enabled HTTP2-only for my APIs. However, when attempting to use health checks I get the following error
HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint.
Setup looks like this
Kestrel:
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2",
"Http": {
"Url": "http://localhost:5020"
}
}
},
Health Check:
public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services)
{
var sqlOptions = services.GetOptions<SqlOptions>("ConnectionStrings");
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");
services.AddHealthChecks()
.AddSqlServer(sqlOptions.DefaultConnection)
.AddRabbitMQ(rabbitConnectionString:
$"amqp://{rabbitMqOptions.UserName}:{rabbitMqOptions.Password}@{rabbitMqOptions.HostName}");
services.AddHealthChecksUI(setup =>
{
setup.SetEvaluationTimeInSeconds(60); // time in seconds between check
setup.AddHealthCheckEndpoint("Basic Health Check", "/healthz");
}).AddInMemoryStorage();
return services;
}
public static WebApplication UseCustomHealthCheck(this WebApplication app)
{
app.UseHealthChecks("/healthz",
new HealthCheckOptions
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
ResultStatusCodes =
{
[HealthStatus.Healthy] = StatusCodes.Status200OK,
[HealthStatus.Degraded] = StatusCodes.Status500InternalServerError,
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable
}
})
.UseHealthChecksUI(options =>
{
options.ApiPath = "/healthcheck";
options.UIPath = "/healthcheck-ui";
});
return app;
}
Dotnet 6.
I managed to resolve this by telling the health check client to specifically use HTTP version 2.0 with the following code.
services.AddHealthChecksUI(setup =>
{
setup.ConfigureApiEndpointHttpclient((sp, client) =>
{
client.DefaultRequestVersion = new Version(2, 0);
});
setup.SetEvaluationTimeInSeconds(60); // time in seconds between check
setup.AddHealthCheckEndpoint("Basic Health Check", "/healthz");
})
.AddInMemoryStorage();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With