h3

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package h3 is mimicry's HTTP/3 client (RFC 9114) on internal/quic, with field sections encoded by internal/qpack. It reproduces the profile's HTTP/3 (profile.HTTP3): SETTINGS and GREASE, when each stream opens, QPACK table use, PRIORITY_UPDATE, header lists and DATA framing.

Each request's frames leave in one flight, in the browser's order (quic.Conn.Cork). A request the server did not process fails with ErrConnUnusable or ErrRejected so it can go on another connection.

Index

Constants

This section is empty.

Variables

View Source
var ErrConnLost = errors.New("h3: connection ended before the response")

ErrConnLost is a request whose connection ended (the server closed it, it timed out, or reset) before the response's headers arrived: the server may or may not have processed it.

View Source
var ErrConnUnusable = errors.New("h3: connection cannot take the request")

ErrConnUnusable is a request the connection did not send: it is going away (the server's GOAWAY), or ended. Nothing of the request was sent, so it may go on another connection.

View Source
var ErrNoConnectUDP = errors.New("h3: the proxy offers no CONNECT-UDP (extended CONNECT with HTTP/3 datagrams)")

ErrNoConnectUDP is a proxy whose connection cannot carry CONNECT-UDP: its SETTINGS allow no extended CONNECT or no HTTP/3 datagrams, or its QUIC takes no DATAGRAM frames.

View Source
var ErrRejected = errors.New("h3: request rejected by the server")

ErrRejected is a request with a body the server did not process (its GOAWAY, or H3_REQUEST_REJECTED): it may go on another connection with a fresh copy of its body.

View Source
var ErrUDPEnded = errors.New("h3: the proxy ended the CONNECT-UDP stream")

ErrUDPEnded is the error of a UDPConn's reads and writes once the proxy has ended its stream or its connection.

Functions

func Head(p *profile.Spec, altHost, altPort string, req *http.Request) ([]qpack.Field, error)

Head returns the field list a connection for p, to the alternative service at altHost and altPort (Options), sends for req (RoundTrip), pseudo-headers first, built as RoundTrip builds it. An error is one RoundTrip returns before sending anything.

func Measured

func Measured(p *profile.Spec, plan *headerorder.Plan) bool

Measured reports whether p covers a request planned as plan over HTTP/3: HTTP3 and QUIC sections and, where its HTTP/3 lists add alt-used, an entry for the request's kind (H3Headers.AltUsed). Other requests go on TCP.

func QPACKConfig

func QPACKConfig(h *profile.HTTP3) qpack.Config

QPACKConfig is how the profile's browser encodes field sections. Without a measured encoder (Safari) it never uses the dynamic table.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a client HTTP/3 connection on a QUIC connection, speaking as the profile's browser does down to the order of its frames on the wire. It is safe for concurrent use.

func New

func New(qc *quic.Conn, p *profile.Spec, opts Options) (*Conn, error)

New starts HTTP/3 on qc, which quic.Dial returned corked, for profile p, which has HTTP3 and QUIC sections. It opens the profile's handshake streams (after the request, for opts.Pending in 0-RTT where the profile sends it first) and serves the server's streams until qc ends.

func (*Conn) CanTakeNewRequest

func (c *Conn) CanTakeNewRequest() bool

CanTakeNewRequest reports whether a new request may start on the connection: it has not ended, failed or received GOAWAY.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection at once with H3_NO_ERROR.

func (*Conn) ConnectUDP added in v0.5.0

func (c *Conn) ConnectUDP(ctx context.Context, authority, path string, fields []profile.Header, peer netip.AddrPort, minPayload int) (*http.Response, *UDPConn, error)

ConnectUDP opens a CONNECT-UDP stream through the proxy the connection reaches, once its SETTINGS have arrived: :method CONNECT, :protocol connect-udp, :scheme https, :authority authority (the proxy) and :path path (the target in the proxy's URI template), the pseudo-header fields in the profile's HTTP/3 order with :protocol after them, then fields. It returns the proxy's response once its headers arrive and, for a 2xx, the stream as a UDPConn whose reads report peer as their source; the stream then outlives ctx. Any other response comes without one, its body the caller's to read and close. A proxy that cannot carry it, or whose datagrams are too small for payloads of minPayload bytes (the connection's packets it carries), fails with ErrNoConnectUDP before anything is sent.

func (*Conn) Discard

func (c *Conn) Discard()

Discard ends the connection without a word to the server, as a QUIC idle timeout ends it.

func (*Conn) Done

func (c *Conn) Done() <-chan struct{}

Done is closed once the QUIC connection has ended.

func (*Conn) EarlyMethod

func (c *Conn) EarlyMethod(method string) bool

EarlyMethod reports whether the profile sends a request with method in 0-RTT (HTTP3.EarlyData.Methods); others made during the handshake wait for it.

func (*Conn) GoneAway

func (c *Conn) GoneAway() bool

GoneAway reports whether the server sent GOAWAY.

func (*Conn) IdleSince

func (c *Conn) IdleSince() (time.Time, bool)

IdleSince reports when the connection's last request ended (or it started), and false while a request is in flight.

func (*Conn) OnClose

func (c *Conn) OnClose(f func())

OnClose runs f once the QUIC connection has ended (Done is closed): at once, on the caller's goroutine, if it has; otherwise on the goroutine that sees it end. f runs with none of c's locks held.

func (*Conn) RoundTrip

func (c *Conn) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip sends req on a new request stream and returns the response once its headers arrive; req's context bounds the whole exchange, body reads included. req.Body is closed, except with ErrConnUnusable, which leaves it for the retry. A 0-RTT request answered 425 Too Early goes again in 1-RTT where the profile retries it (HTTP3.EarlyData) and its body can be re-read.

type Options

type Options struct {
	// AltHost and AltPort are the alternative service the connection
	// reaches (alt-used).
	AltHost, AltPort string
	// Pending: the connection was dialled for a request about to be sent,
	// which goes before the control and QPACK streams in 0-RTT where the
	// profile says so (Firefox).
	Pending bool
	// Clock times how long the connection has been idle (IdleSince); nil
	// is the real clock.
	Clock clockwork.Clock
}

Options are what a connection needs besides the QUIC connection and the profile.

type UDPConn added in v0.5.0

type UDPConn struct {
	// contains filtered or unexported fields
}

UDPConn is a CONNECT-UDP stream as a net.PacketConn: a write sends its bytes to the proxy's target, whatever address it names, in one HTTP/3 datagram; a read returns a UDP payload from the target, reported from the peer given to ConnectUDP. Datagrams with a context ID other than 0 are dropped. Once the proxy ends the stream or the connection, reads and writes fail with ErrUDPEnded. Close ends the stream, not the connection.

func (*UDPConn) Close added in v0.5.0

func (u *UDPConn) Close() error

Close ends the stream (H3_REQUEST_CANCELLED both ways); the connection stays open.

func (*UDPConn) LocalAddr added in v0.5.0

func (u *UDPConn) LocalAddr() net.Addr

LocalAddr is the unspecified address: the UDPConn has no socket of its own.

func (*UDPConn) ReadFrom added in v0.5.0

func (u *UDPConn) ReadFrom(p []byte) (int, net.Addr, error)

ReadFrom reads the next UDP payload from the target into p, waiting until one arrives, the stream ends or the read deadline passes.

func (*UDPConn) SetDeadline added in v0.5.0

func (u *UDPConn) SetDeadline(t time.Time) error

SetDeadline sets the read deadline; writes never wait.

func (*UDPConn) SetReadDeadline added in v0.5.0

func (u *UDPConn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline, for reads under way too.

func (*UDPConn) SetWriteDeadline added in v0.5.0

func (u *UDPConn) SetWriteDeadline(time.Time) error

SetWriteDeadline does nothing: writes never wait.

func (*UDPConn) WriteTo added in v0.5.0

func (u *UDPConn) WriteTo(b []byte, _ net.Addr) (int, error)

WriteTo sends b to the target in one HTTP/3 datagram; addr is ignored. It never waits: a datagram the connection has no room for is dropped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL