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 ¶
- Variables
- func Head(p *profile.Spec, altHost, altPort string, req *http.Request) ([]qpack.Field, error)
- func Measured(p *profile.Spec, plan *headerorder.Plan) bool
- func QPACKConfig(h *profile.HTTP3) qpack.Config
- type Conn
- func (c *Conn) CanTakeNewRequest() bool
- func (c *Conn) Close() error
- func (c *Conn) ConnectUDP(ctx context.Context, authority, path string, fields []profile.Header, ...) (*http.Response, *UDPConn, error)
- func (c *Conn) Discard()
- func (c *Conn) Done() <-chan struct{}
- func (c *Conn) EarlyMethod(method string) bool
- func (c *Conn) GoneAway() bool
- func (c *Conn) IdleSince() (time.Time, bool)
- func (c *Conn) OnClose(f func())
- func (c *Conn) RoundTrip(req *http.Request) (*http.Response, error)
- type Options
- type UDPConn
- func (u *UDPConn) Close() error
- func (u *UDPConn) LocalAddr() net.Addr
- func (u *UDPConn) ReadFrom(p []byte) (int, net.Addr, error)
- func (u *UDPConn) SetDeadline(t time.Time) error
- func (u *UDPConn) SetReadDeadline(t time.Time) error
- func (u *UDPConn) SetWriteDeadline(time.Time) error
- func (u *UDPConn) WriteTo(b []byte, _ net.Addr) (int, error)
Constants ¶
This section is empty.
Variables ¶
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.
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.
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.
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.
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 ¶
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.
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 ¶
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 ¶
CanTakeNewRequest reports whether a new request may start on the connection: it has not ended, failed or received GOAWAY.
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 ¶
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) IdleSince ¶
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 ¶
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
Close ends the stream (H3_REQUEST_CANCELLED both ways); the connection stays open.
func (*UDPConn) LocalAddr ¶ added in v0.5.0
LocalAddr is the unspecified address: the UDPConn has no socket of its own.
func (*UDPConn) ReadFrom ¶ added in v0.5.0
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
SetDeadline sets the read deadline; writes never wait.
func (*UDPConn) SetReadDeadline ¶ added in v0.5.0
SetReadDeadline sets the read deadline, for reads under way too.
func (*UDPConn) SetWriteDeadline ¶ added in v0.5.0
SetWriteDeadline does nothing: writes never wait.