# README

HTTP/3

PkgGoDev

This package implements HTTP/3 (RFC 9114), including QPACK (RFC 9204). It aims to provide feature parity with the standard library's HTTP/1.1 and HTTP/2 implementation.

Serving HTTP/3

The easiest way to start an HTTP/3 server is using

mux := http.NewServeMux()
// ... add HTTP handlers to mux ...
// If mux is nil, the http.DefaultServeMux is used.
http3.ListenAndServeQUIC("0.0.0.0:443", "/path/to/cert", "/path/to/key", mux)

ListenAndServeQUIC is a convenience function. For more configurability, set up an http3.Server explicitly:

server := http3.Server{
	Handler:    mux,
	Addr:       "0.0.0.0:443",
	TLSConfig:  http3.ConfigureTLSConfig(&tls.Config{}), // use your tls.Config here
	QuicConfig: &quic.Config{},
}
err := server.ListenAndServe()

The http3.Server provides a number of configuration options, please refer to the documentation for a complete list. The QuicConfig is used to configure the underlying QUIC connection. More details can be found in the documentation of the QUIC package.

It is also possible to manually set up a quic.Transport, and then pass the listener to the server. This is useful when you want to set configuration options on the quic.Transport.

tr := quic.Transport{Conn: conn}
tlsConf := http3.ConfigureTLSConfig(&tls.Config{})  // use your tls.Config here
quicConf := &quic.Config{} // QUIC connection options
server := http3.Server{}
ln, _ := tr.ListenEarly(tlsConf, quicConf)
server.ServeListener(ln)

Alternatively, it is also possible to pass fully established QUIC connections to the HTTP/3 server. This is useful if the QUIC server offers multiple ALPNs (via NextProtos in the tls.Config).

tr := quic.Transport{Conn: conn}
tlsConf := http3.ConfigureTLSConfig(&tls.Config{})  // use your tls.Config here
quicConf := &quic.Config{} // QUIC connection options
server := http3.Server{}
// alternatively, use tr.ListenEarly to accept 0-RTT connections
ln, _ := tr.Listen(tlsConf, quicConf)
for {
	c, _ := ln.Accept()
	switch c.ConnectionState().TLS.NegotiatedProtocol {
	case http3.NextProtoH3:
		go server.ServeQUICConn(c) 
        // ... handle other protocols ...  
	}
}

Dialing HTTP/3

This package provides a http.RoundTripper implementation that can be used on the http.Client:

&http3.RoundTripper{
	TLSClientConfig: &tls.Config{},  // set a TLS client config, if desired
	QuicConfig:      &quic.Config{}, // QUIC connection options
}
defer roundTripper.Close()
client := &http.Client{
	Transport: roundTripper,
}

The http3.RoundTripper provides a number of configuration options, please refer to the documentation for a complete list.

To use a custom quic.Transport, the function used to dial new QUIC connections can be configured:

tr := quic.Transport{}
roundTripper := &http3.RoundTripper{
	TLSClientConfig: &tls.Config{},  // set a TLS client config, if desired 
	QuicConfig:      &quic.Config{}, // QUIC connection options 
	Dial: func(ctx context.Context, addr string, tlsConf *tls.Config, quicConf *quic.Config) (quic.EarlyConnection, error) {
		a, err := net.ResolveUDPAddr("udp", addr)
		if err != nil {
			return nil, err
		}
		return tr.DialEarly(ctx, a, tlsConf, quicConf)
	},
}

Using the same UDP Socket for Server and Roundtripper

Since QUIC demultiplexes packets based on their connection IDs, it is possible allows running a QUIC server and client on the same UDP socket. This also works when using HTTP/3: HTTP requests can be sent from the same socket that a server is listening on.

To achieve this using this package, first initialize a single quic.Transport, and pass a quic.EarlyListner obtained from that transport to http3.Server.ServeListener, and use the DialEarly function of the transport as the Dial function for the http3.RoundTripper.

QPACK

HTTP/3 utilizes QPACK (RFC 9204) for efficient HTTP header field compression. Our implementation, available atquic-go/qpack, provides a minimal implementation of the protocol.

While the current implementation is a fully interoperable implementation of the QPACK protocol, it only uses the static compression table. The dynamic table would allow for more effective compression of frequently transmitted header fields. This can be particularly beneficial in scenarios where headers have considerable redundancy or in high-throughput environments.

If you think that your application would benefit from higher compression efficiency, or if you're interested in contributing improvements here, please let us know in #2424.

# Functions

ConfigureTLSConfig creates a new tls.Config which can be used to create a quic.Listener meant for serving http3.
No description provided by the author
ListenAndServe listens on the given network address for both TLS/TCP and QUIC connections in parallel.
ListenAndServeQUIC listens on the UDP network address addr and calls the handler for HTTP/3 requests on incoming connections.
ParseCapsule parses the header of a Capsule.
WriteCapsule writes a capsule.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
MethodGet0RTT allows a GET request to be sent using 0-RTT.
NextProtoH3 is the ALPN protocol negotiated during the TLS handshake, for QUIC v1 and v2.

# Variables

ErrNoAltSvcPort is the error returned by SetQuicHeaders when no port was found for Alt-Svc to announce.
ErrNoCachedConn is returned when RoundTripper.OnlyCachedConn is set.
RemoteAddrContextKey is a context key.
ServerContextKey is a context key.

# Structs

Error is returned from the round tripper (for HTTP clients) and inside the HTTP handler (for HTTP servers) if an HTTP/3 error occurs.
RoundTripOpt are options for the Transport.RoundTripOpt method.
RoundTripper implements the http.RoundTripper interface.
Server is a HTTP/3 server.
Settings are HTTP/3 settings that apply to the underlying connection.
No description provided by the author

# Interfaces

A Hijacker allows hijacking of the stream creating part of a quic.Session from a http.Response.Body.
The HTTPStreamer allows taking over a HTTP/3 stream.
A QUICEarlyListener listens for incoming QUIC connections.
No description provided by the author

# Type aliases

CapsuleType is the type of the capsule.
No description provided by the author
FrameType is the frame type of a HTTP/3 frame.
A Stream is a HTTP/3 stream.
StreamType is the stream type of a unidirectional stream.