h3

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 19 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 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.

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) 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.

Jump to

Keyboard shortcuts

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