HTTP/3
HTTP/3 is an HTTP protocol that runs over QUIC instead of TCP.
Ktor provides experimental HTTP/3 support with the Netty server engine.
Enable HTTP/3
HTTP/3 always uses TLS, so you need to configure at least one SSL connector.
To enable HTTP/3, call the enableHttp3() function in the Netty engine configuration:
For each SSL connector, Ktor binds an HTTP/3 endpoint to the same host and port over UDP. HTTP/1.1 and HTTP/2 continue to use TCP on that port.
Configure HTTP/3
To customize HTTP/3 and QUIC behavior, use the available options inside the enableHttp3() configuration block:
The following options are available:
quicTokenHandlerDefaults to
null.Specifies a
QuicTokenHandlerfor QUIC address validation. UseHmacQuicTokenHandlerto enable HMAC-based retry tokens.quicMaxIdleTimeoutDefaults to
30.seconds.Specifies how long a QUIC connection can remain idle before it is closed. Must be greater than
0.quicInitialMaxDataDefaults to
10_000_000.Specifies the initial value of the connection's maximum data limit. Must be greater than
0.quicInitialMaxStreamDataBidirectionalLocalDefaults to
1_000_000.Specifies the initial flow-control limit for locally initiated bidirectional streams. Must be greater than
0.quicInitialMaxStreamDataBidirectionalRemoteDefaults to
1_000_000.Specifies the initial flow-control limit for remotely initiated bidirectional streams. Must be greater than
0.quicInitialMaxStreamsBidirectionalDefaults to
100.Specifies the initial number of bidirectional streams that can be opened. Must be greater than
0.udpSocketCountDefaults to
1.Specifies the number of UDP sockets for the HTTP/3 endpoint. Values greater than
1require platform support forSO_REUSEPORT.udpReceiveBufferSizeDefaults to
0.Specifies the UDP receive buffer (
SO_RCVBUF) size in bytes. If you set0, the operating system uses its default.udpSendBufferSizeDefaults to
0.Specifies the UDP send buffer (
SO_SNDBUF) size in bytes. If you set0, the operating system uses its default.
These options apply only to HTTP/3 connections and don't affect HTTP/1.1 or HTTP/2.
Configure the QUIC server codec
For advanced Netty configuration, use the configureQuicServerCodec option to customize the underlying QuicServerCodecBuilder:
Use this option only when you need low-level QUIC transport configuration.