http3

package
v3.52.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MethodGet0RTT allows a GET request to be sent using 0-RTT.
	// Note that 0-RTT doesn't provide replay protection and should only be used for idempotent requests.
	MethodGet0RTT = "GET_0RTT"
	// MethodHead0RTT allows a HEAD request to be sent using 0-RTT.
	// Note that 0-RTT doesn't provide replay protection and should only be used for idempotent requests.
	MethodHead0RTT = "HEAD_0RTT"
)
View Source
const (
	VersionUnknown quic.Version = math.MaxUint32

	Version1 quic.Version = 0x1
	Version2 quic.Version = 0x6b3343cf
)

The version numbers, making grepping easier

View Source
const NextProtoH3 = "h3"

NextProtoH3 is the ALPN protocol negotiated during the TLS handshake, for QUIC v1 and v2.

Variables

View Source
var ErrNoCachedConn = errors.New("http3: no cached connection was available")

ErrNoCachedConn is returned when Transport.OnlyCachedConn is set

View Source
var SupportedVersions = []quic.Version{Version1, Version2}

SupportedVersions lists the versions that the server supports must be in sorted descending order

Functions

This section is empty.

Types

type ClientConn added in v3.51.0

type ClientConn struct {
	*transport.Options
	// contains filtered or unexported fields
}

ClientConn is an HTTP/3 client doing requests to a single remote server.

func (*ClientConn) CloseWithError added in v3.51.0

func (c *ClientConn) CloseWithError(code quic.ApplicationErrorCode, msg string) error

func (*ClientConn) Context added in v3.51.0

func (c *ClientConn) Context() context.Context

Context returns the context of the underlying QUIC connection.

func (*ClientConn) OpenRequestStream added in v3.51.0

func (c *ClientConn) OpenRequestStream(ctx context.Context) (RequestStream, error)

OpenRequestStream opens a new request stream on the HTTP/3 connection.

func (*ClientConn) ReceivedSettings added in v3.51.0

func (c *ClientConn) ReceivedSettings() <-chan struct{}

ReceivedSettings returns a channel that is closed once the peer's SETTINGS frame was received. Settings can be optained from the Settings method after the channel was closed.

func (*ClientConn) RoundTrip added in v3.51.0

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

RoundTrip executes a request and returns a response

func (*ClientConn) Settings added in v3.51.0

func (c *ClientConn) Settings() *Settings

Settings returns the settings received on this connection. It is only valid to call this function after the channel returned by ReceivedSettings was closed.

type Connection added in v3.46.0

type Connection interface {
	OpenStream() (quic.Stream, error)
	OpenStreamSync(context.Context) (quic.Stream, error)
	OpenUniStream() (quic.SendStream, error)
	OpenUniStreamSync(context.Context) (quic.SendStream, error)
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	CloseWithError(quic.ApplicationErrorCode, string) error
	Context() context.Context
	ConnectionState() quic.ConnectionState

	// ReceivedSettings returns a channel that is closed once the client's SETTINGS frame was received.
	ReceivedSettings() <-chan struct{}
	// Settings returns the settings received on this connection.
	Settings() *Settings
}

Connection is an HTTP/3 connection. It has all methods from the quic.Connection expect for AcceptStream, AcceptUniStream, SendDatagram and ReceiveDatagram.

type ErrCode added in v3.42.3

type ErrCode quic.ApplicationErrorCode
const (
	ErrCodeNoError              ErrCode = 0x100
	ErrCodeGeneralProtocolError ErrCode = 0x101
	ErrCodeInternalError        ErrCode = 0x102
	ErrCodeStreamCreationError  ErrCode = 0x103
	ErrCodeClosedCriticalStream ErrCode = 0x104
	ErrCodeFrameUnexpected      ErrCode = 0x105
	ErrCodeFrameError           ErrCode = 0x106
	ErrCodeExcessiveLoad        ErrCode = 0x107
	ErrCodeIDError              ErrCode = 0x108
	ErrCodeSettingsError        ErrCode = 0x109
	ErrCodeMissingSettings      ErrCode = 0x10a
	ErrCodeRequestRejected      ErrCode = 0x10b
	ErrCodeRequestCanceled      ErrCode = 0x10c
	ErrCodeRequestIncomplete    ErrCode = 0x10d
	ErrCodeMessageError         ErrCode = 0x10e
	ErrCodeConnectError         ErrCode = 0x10f
	ErrCodeVersionFallback      ErrCode = 0x110
	ErrCodeDatagramError        ErrCode = 0x33
)

func (ErrCode) String added in v3.42.3

func (e ErrCode) String() string

type Error added in v3.42.3

type Error struct {
	Remote       bool
	ErrorCode    ErrCode
	ErrorMessage string
}

Error is returned from the round tripper (for HTTP clients) and inside the HTTP handler (for HTTP servers) if an HTTP/3 error occurs. See section 8 of RFC 9114.

func (*Error) Error added in v3.42.3

func (e *Error) Error() string

func (*Error) Is added in v3.51.0

func (e *Error) Is(target error) bool

type FrameType

type FrameType uint64

FrameType is the frame type of a HTTP/3 frame

type Hijacker

type Hijacker interface {
	Connection() Connection
}

A Hijacker allows hijacking of the stream creating part of a quic.Session from a http.Response.Body. It is used by WebTransport to create WebTransport streams after a session has been established.

type Perspective added in v3.46.0

type Perspective int

Perspective determines if we're acting as a server or a client

const (
	PerspectiveServer Perspective = 1
	PerspectiveClient Perspective = 2
)

the perspectives

func (Perspective) Opposite added in v3.46.0

func (p Perspective) Opposite() Perspective

Opposite returns the perspective of the peer

func (Perspective) String added in v3.46.0

func (p Perspective) String() string

type RequestStream added in v3.46.0

type RequestStream interface {
	Stream

	// SendRequestHeader sends the HTTP request.
	// It is invalid to call it more than once.
	// It is invalid to call it after Write has been called.
	SendRequestHeader(req *http.Request) error

	// ReadResponse reads the HTTP response from the stream.
	// It is invalid to call it more than once.
	// It doesn't set Response.Request and Response.TLS.
	// It is invalid to call it after Read has been called.
	ReadResponse() (*http.Response, error)
}

A RequestStream is an HTTP/3 request stream. When writing to and reading from the stream, data is framed in HTTP/3 DATA frames.

type RoundTripOpt

type RoundTripOpt struct {
	// OnlyCachedConn controls whether the Transport may create a new QUIC connection.
	// If set true and no cached connection is available, RoundTripOpt will return ErrNoCachedConn.
	OnlyCachedConn bool
}

RoundTripOpt are options for the Transport.RoundTripOpt method.

type RoundTripper deprecated

type RoundTripper = Transport

Deprecated: RoundTripper was renamed to Transport.

type ServerStreamType added in v3.46.0

type ServerStreamType uint64

StreamType is the stream type of a unidirectional stream.

type Settings added in v3.46.0

type Settings struct {
	// Support for HTTP/3 datagrams (RFC 9297)
	EnableDatagrams bool
	// Extended CONNECT, RFC 9220
	EnableExtendedConnect bool
	// Other settings, defined by the application
	Other map[uint64]uint64
}

Settings are HTTP/3 settings that apply to the underlying connection.

type SingleDestinationRoundTripper deprecated added in v3.46.0

type SingleDestinationRoundTripper = ClientConn

Deprecated: SingleDestinationRoundTripper was renamed to ClientConn. It can be obtained by calling NewClientConn on a Transport.

type Stream

type Stream interface {
	quic.Stream

	SendDatagram([]byte) error
	ReceiveDatagram(context.Context) ([]byte, error)
}

A Stream is an HTTP/3 request stream. When writing to and reading from the stream, data is framed in HTTP/3 DATA frames.

type StreamID added in v3.46.0

type StreamID int64

A StreamID in QUIC

const InvalidStreamID StreamID = -1

InvalidPacketNumber is a stream ID that is invalid. The first valid stream ID in QUIC is 0.

func (StreamID) InitiatedBy added in v3.46.0

func (s StreamID) InitiatedBy() Perspective

InitiatedBy says if the stream was initiated by the client or by the server

func (StreamID) StreamNum added in v3.46.0

func (s StreamID) StreamNum() StreamNum

StreamNum returns how many streams in total are below this Example: for stream 9 it returns 3 (i.e. streams 1, 5 and 9)

func (StreamID) Type added in v3.46.0

func (s StreamID) Type() StreamType

Type says if this is a unidirectional or bidirectional stream

type StreamNum added in v3.46.0

type StreamNum int64

StreamNum is the stream number

const (
	// InvalidStreamNum is an invalid stream number.
	InvalidStreamNum = -1
	// MaxStreamCount is the maximum stream count value that can be sent in MAX_STREAMS frames
	// and as the stream count in the transport parameters
	MaxStreamCount StreamNum = 1 << 60
)

func (StreamNum) StreamID added in v3.46.0

func (s StreamNum) StreamID(stype StreamType, pers Perspective) StreamID

StreamID calculates the stream ID.

type StreamType

type StreamType uint8

StreamType encodes if this is a unidirectional or bidirectional stream

const (
	// StreamTypeUni is a unidirectional stream
	StreamTypeUni StreamType = iota
	// StreamTypeBidi is a bidirectional stream
	StreamTypeBidi
)

type Transport added in v3.51.0

type Transport struct {
	*transport.Options
	// TLSClientConfig specifies the TLS configuration to use with
	// tls.Client. If nil, the default configuration is used.
	TLSClientConfig *tls.Config

	// QUICConfig is the quic.Config used for dialing new connections.
	// If nil, reasonable default values will be used.
	QUICConfig *quic.Config

	// Dial specifies an optional dial function for creating QUIC
	// connections for requests.
	// If Dial is nil, a UDPConn will be created at the first request
	// and will be reused for subsequent connections to other servers.
	Dial func(ctx context.Context, addr string, tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlyConnection, error)

	// Enable support for HTTP/3 datagrams (RFC 9297).
	// If a QUICConfig is set, datagram support also needs to be enabled on the QUIC layer by setting EnableDatagrams.
	EnableDatagrams bool

	// Additional HTTP/3 settings.
	// It is invalid to specify any settings defined by RFC 9114 (HTTP/3) and RFC 9297 (HTTP Datagrams).
	AdditionalSettings map[uint64]uint64

	// MaxResponseHeaderBytes specifies a limit on how many response bytes are
	// allowed in the server's response header.
	// Zero means to use a default limit.
	MaxResponseHeaderBytes int64

	// DisableCompression, if true, prevents the Transport from requesting compression with an
	// "Accept-Encoding: gzip" request header when the Request contains no existing Accept-Encoding value.
	// If the Transport requests gzip on its own and gets a gzipped response, it's transparently
	// decoded in the Response.Body.
	// However, if the user explicitly requested gzip it is not automatically uncompressed.
	DisableCompression bool

	StreamHijacker    func(FrameType, quic.ConnectionTracingID, quic.Stream, error) (hijacked bool, err error)
	UniStreamHijacker func(StreamType, quic.ConnectionTracingID, quic.ReceiveStream, error) (hijacked bool)

	Logger *slog.Logger
	// contains filtered or unexported fields
}

Transport implements the http.RoundTripper interface

func (*Transport) AddConn added in v3.51.0

func (t *Transport) AddConn(ctx context.Context, addr string) error

AddConn add a http3 connection, dial new conn if not exists.

func (*Transport) Close added in v3.51.0

func (t *Transport) Close() error

Close closes the QUIC connections that this Transport has used.

func (*Transport) CloseIdleConnections added in v3.51.0

func (t *Transport) CloseIdleConnections()

CloseIdleConnections closes any QUIC connections in the transport's pool that are currently idle. An idle connection is one that was previously used for requests but is now sitting unused. This method does not interrupt any connections currently in use. It also does not affect connections obtained via NewClientConn.

func (*Transport) NewClientConn added in v3.51.0

func (t *Transport) NewClientConn(conn quic.Connection) *ClientConn

NewClientConn creates a new HTTP/3 client connection on top of a QUIC connection. Most users should use RoundTrip instead of creating a connection directly. Specifically, it is not needed to perform GET, POST, HEAD and CONNECT requests.

Obtaining a ClientConn is only needed for more advanced use cases, such as using Extended CONNECT for WebTransport or the various MASQUE protocols.

func (*Transport) RoundTrip added in v3.51.0

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip does a round trip.

func (*Transport) RoundTripOnlyCachedConn added in v3.51.0

func (t *Transport) RoundTripOnlyCachedConn(req *http.Request) (*http.Response, error)

RoundTripOnlyCachedConn round trip only cached conn.

func (*Transport) RoundTripOpt added in v3.51.0

func (t *Transport) RoundTripOpt(req *http.Request, opt RoundTripOpt) (*http.Response, error)

RoundTripOpt is like RoundTrip, but takes options.

Jump to

Keyboard shortcuts

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