skip to content

An ASP.NET Core 10 Kestrel endpoint sets Protocols to Http1AndHttp2AndHttp3, yet clients only ever use HTTP/1.1; what must be true for Kestrel to serve HTTP/2 and HTTP/3?

level: seniorimportance: nice to knowfreq 22%

answer

  1. default Protocols is Http1AndHttp2
  2. no TLS plus Http1: the others drop
  3. QuicListener.IsSupported, libmsquic
  4. UDP on the same port number
  5. alt-svc header, DisableAltSvcHeader

basics

~20 s

The endpoint must use TLS: without it, Kestrel serves HTTP/1.1 and logs that HTTP/2 and HTTP/3 are disabled. HTTP/3 additionally needs a QUIC-capable platform (MsQuic), the same port open for UDP, and clients learning of it through the alt-svc header.

solid answer

~40 s

`ListenOptions.Protocols` defaults to `Http1AndHttp2`; HTTP/3 is opt-in. Both newer versions depend on TLS: HTTP/2 is chosen through ALPN during the TLS handshake, so on a cleartext endpoint that also allows HTTP/1.1, Kestrel turns HTTP/2 and HTTP/3 off and logs warnings saying connections will use HTTP/1.1. An HTTP/3-only cleartext endpoint fails at startup with "HTTP/3 requires HTTPS." HTTP/3 also needs QUIC: `UseQuic` registers the transport only when `QuicListener.IsSupported`, which means Windows 11 / Server 2022 or later, or Linux with `libmsquic` installed. Without it, Kestrel quietly serves HTTP/1.1 and HTTP/2 and sends no `alt-svc` header. Finally, UDP traffic to the same port must reach the process, and clients switch only after an `alt-svc` header on an earlier TCP response.

code

csharp · 16 lines
csharp
using Microsoft.AspNetCore.Server.Kestrel.Core;

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureKestrel(options =>
{
    options.ListenAnyIP(8443, listen =>
    {
        listen.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
        listen.UseHttps("/certs/ingest.pfx", builder.Configuration["Certs:IngestPassword"]);
    });
});

var app = builder.Build();
app.MapPost("/readings", () => Results.Accepted());
app.Run();

go deeper

for a junior

Recall that Kestrel endpoints default to HTTP/1.1 plus HTTP/2, and that HTTP/3 must be switched on with HttpProtocols.Http1AndHttp2AndHttp3 over HTTPS.

for a middle

Explain why a cleartext endpoint that allows HTTP/1.1 drops HTTP/2, how Http2-only cleartext works for gRPC, and what the alt-svc header does.

for a senior

Diagnose missing HTTP/3 end to end: the bind-time warnings, QuicListener.IsSupported and libmsquic, UDP through firewalls and containers, and CreateSlimBuilder without UseQuic.

for a principal

Judge whether HTTP/3 belongs in Kestrel or at the edge, given UDP support across the network path and who operates the TLS termination point.

## What `Protocols` controls Every Kestrel endpoint (`ListenOptions`) carries an `HttpProtocols` value, settable in code or as `Protocols` in `Kestrel:Endpoints:<name>` and `Kestrel:EndpointDefaults`. The enum is a set of flags: | Value | Meaning | |---|---| | `Http1` | HTTP/1.x only | | `Http2` | HTTP/2 only | | `Http1AndHttp2` | **the default** for every endpoint | | `Http3` | HTTP/3 only | | `Http1AndHttp2AndHttp3` | all three; the recommended way to enable HTTP/3 | The value is a request, not a guarantee. When Kestrel binds the endpoint it filters out combinations the transport cannot serve. ## Rule 1: HTTP/2 and HTTP/3 depend on TLS On a TLS endpoint, client and server agree on HTTP/2 or HTTP/1.1 through **ALPN** inside the handshake. On a cleartext endpoint there is no handshake to negotiate in, so Kestrel applies these rules when it binds: 1. Cleartext and `Http1` included: HTTP/2 and HTTP/3 are switched off. If you set `Protocols` explicitly, Kestrel logs warnings such as "HTTP/2 is not enabled for {Endpoint}... Connections to this endpoint will use HTTP/1.1." 2. Cleartext and `Http2` alone: Kestrel speaks HTTP/2 to clients that open with it directly. This is how an internal gRPC service listens without TLS; the `grpc` project template sets `Kestrel:EndpointDefaults:Protocols` to `Http2`. 3. Cleartext and `Http3` alone: startup throws `InvalidOperationException` "HTTP/3 requires HTTPS." The symptom in the question (HTTP/1.1 only) is most often rule 1: the endpoint is `http://`, perhaps because TLS ends at a proxy in front of it. ## Rule 2: HTTP/3 needs QUIC on the host HTTP/3 runs over QUIC, which .NET implements through `System.Net.Quic` on top of the native **MsQuic** library. `WebApplication.CreateBuilder` registers Kestrel with `UseKestrel()`, which calls `UseQuic(...)`; that extension adds the QUIC transport only when `QuicListener.IsSupported` is true: - **Windows:** Windows 11, Windows Server 2022 or later; MsQuic ships with .NET. - **Linux:** the `libmsquic` package must be installed in the host or container image. - Other platforms are outside the tested matrix. If QUIC is unavailable and the endpoint also allows HTTP/1.1 or HTTP/2, Kestrel binds TCP only and **omits the `alt-svc` header**, with no error at startup. If HTTP/3 is the only protocol, startup throws "Unable to bind an HTTP/3 endpoint. This could be because QUIC has not been configured using UseQuic, or the platform doesn't support QUIC or HTTP/3." `WebApplication.CreateSlimBuilder` registers only `UseKestrelCore()`, which does not add the QUIC transport; call `builder.WebHost.UseQuic()` yourself (and `builder.WebHost.UseKestrelHttpsConfiguration()` if startup reports that HTTPS configuration is missing). ## Rule 3: UDP must reach the process QUIC uses **UDP** on the same port number as the TCP endpoint. For the sensor-telemetry ingest on 8443, that means: - the host firewall allows UDP 8443; - a container publishes `8443/udp` as well as `8443/tcp`; - every load balancer or proxy in front passes UDP through, or terminates HTTP/3 itself. ## Rule 4: clients find HTTP/3 through `alt-svc` Kestrel adds an `alt-svc` response header on HTTP/1.1 and HTTP/2 responses from an HTTP/3-enabled endpoint, so the first request travels over TCP and later ones may switch. `ListenOptions.DisableAltSvcHeader = true` turns the header off. The older `KestrelServerOptions.EnableAltSvc` property is obsolete as an error and no longer has any effect. ## A working configuration ```csharp builder.WebHost.ConfigureKestrel(options => { options.ListenAnyIP(8443, listen => { listen.Protocols = HttpProtocols.Http1AndHttp2AndHttp3; listen.UseHttps("/certs/ingest.pfx", certificatePassword); }); }); ``` ## HTTP/3 and the rest of Kestrel - **Limits:** `KestrelServerLimits.Http3` holds HTTP/3-specific limits such as `MaxRequestHeaderFieldSize`, and QUIC transport settings (stream counts, buffer sizes, backlog) live in `QuicTransportOptions`, configured through `builder.WebHost.UseQuic(o => ...)`. - **TLS callbacks:** `HttpsConnectionAdapterOptions.OnAuthenticate` is not supported for HTTP/3 and makes binding fail; certificate selection through `ServerCertificateSelector` or the `Sni` section works for both TCP and QUIC. - **Connection limits:** `MaxConcurrentConnections` counts QUIC connections as well as TCP ones. ## Checklist when HTTP/3 does not appear - Is the endpoint HTTPS, and does the log carry "HTTP/3 is not enabled" warnings? - Does the response carry `alt-svc`? If not, QUIC is not registered or not supported on this host. - Is UDP on the port open end to end? - Was the app built with `CreateSlimBuilder` without `UseQuic`? Keep HTTP/1.1 and HTTP/2 enabled alongside HTTP/3; networks that block UDP still need a TCP path.

  • How does an internal gRPC service run HTTP/2 on Kestrel without TLS?
    It sets the endpoint's `Protocols` to `Http2` alone. With `Http1` excluded, Kestrel accepts HTTP/2 directly on a cleartext connection; the `grpc` template does this through `Kestrel:EndpointDefaults:Protocols`. With `Http1AndHttp2` on cleartext, HTTP/2 is dropped and HTTP/1.1 is served.
  • Why might HTTP/3 work locally on Windows 11 but not in the Linux container?
    MsQuic ships with .NET on Windows, but on Linux `QuicListener.IsSupported` is false until `libmsquic` is installed. Without it `UseQuic` registers no transport, so Kestrel serves HTTP/1.1 and HTTP/2 and omits `alt-svc`. The container also has to publish the port for UDP.
  • Can different host names on one Kestrel port offer different protocols?
    Yes. An entry in the endpoint's `Sni` section can set its own `Protocols`, which Kestrel applies through ALPN for connections that requested that host name, falling back to the endpoint's `Protocols` when the entry leaves it out.

  • Setting Http1AndHttp2 on an http:// endpoint gives clients HTTP/2.
  • Kestrel enables HTTP/3 by default on every HTTPS endpoint.
  • HTTP/3 shares the TCP port, so no firewall change is needed.
  • Without QUIC support, Kestrel fails to start an Http1AndHttp2AndHttp3 endpoint.
  • Setting KestrelServerOptions.EnableAltSvc is how you advertise HTTP/3.

Assumes ASP.NET Core 10; HTTP/3 stays opt-in per endpoint, and KestrelServerOptions.EnableAltSvc is obsolete as an error in favour of ListenOptions.DisableAltSvcHeader.