http2

package
v0.0.0-...-08bc4dc Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClientPreface is the string that must be sent by new
	// connections from clients.
	ClientPreface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"

	// NextProtoTLS is the NPN/ALPN protocol negotiated during
	// HTTP/2's TLS setup.
	NextProtoTLS = "h2"
)

Variables

View Source
var DebugGoroutines = os.Getenv("DEBUG_HTTP2_GOROUTINES") == "1"
View Source
var ErrNoCachedConn error = noCachedConnError{}
View Source
var (
	VerboseLogs bool
)

Functions

func IsNoCachedConnError

func IsNoCachedConnError(err error) bool

IsNoCachedConnError reports whether err is of type noCachedConnError or its equivalent renamed type in net/http2's h2_bundle.go. Both types may coexist in the same running program.

Types

type ClientConn

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

ClientConn is the state of a single HTTP/2 client connection to an HTTP/2 server.

func (*ClientConn) CanTakeNewRequest

func (cc *ClientConn) CanTakeNewRequest() bool

CanTakeNewRequest reports whether the connection can take a new request, meaning it has not been closed or received or sent a GOAWAY.

If the caller is going to immediately make a new request on this connection, use ReserveNewRequest instead.

func (*ClientConn) Close

func (cc *ClientConn) Close() error

Close closes the client connection immediately.

In-flight requests are interrupted. For a graceful shutdown, use Shutdown instead.

func (*ClientConn) Ping

func (cc *ClientConn) Ping(ctx context.Context) error

Ping sends a PING frame to the server and waits for the ack.

func (*ClientConn) ReserveNewRequest

func (cc *ClientConn) ReserveNewRequest() bool

ReserveNewRequest is like CanTakeNewRequest but also reserves a concurrent stream in cc. The reservation is decremented on the next call to RoundTrip.

func (*ClientConn) RoundTrip

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

func (*ClientConn) SetDoNotReuse

func (cc *ClientConn) SetDoNotReuse()

SetDoNotReuse marks cc as not reusable for future HTTP requests.

func (*ClientConn) Shutdown

func (cc *ClientConn) Shutdown(ctx context.Context) error

Shutdown gracefully closes the client connection, waiting for running streams to complete.

type ClientConnPool

type ClientConnPool interface {
	// GetClientConn returns a specific HTTP/2 connection (usually
	// a TLS-TCP connection) to an HTTP/2 server. On success, the
	// returned ClientConn accounts for the upcoming RoundTrip
	// call, so the caller should not omit it. If the caller needs
	// to, ClientConn.RoundTrip can be called with a bogus
	// new(http.Request) to release the stream reservation.
	GetClientConn(req *http.Request, addr string, dialOnMiss bool) (*ClientConn, error)
	MarkDead(*ClientConn)
	CloseIdleConnections()
	AddConnIfNeeded(key string, t *Transport, c net.Conn) (used bool, err error)
}

ClientConnPool manages a pool of HTTP/2 client connections.

type ClientConnState

type ClientConnState struct {
	// Closed is whether the connection is closed.
	Closed bool

	// Closing is whether the connection is in the process of
	// closing. It may be closing due to shutdown, being a
	// single-use connection, being marked as DoNotReuse, or
	// having received a GOAWAY frame.
	Closing bool

	// StreamsActive is how many streams are active.
	StreamsActive int

	// StreamsReserved is how many streams have been reserved via
	// ClientConn.ReserveNewRequest.
	StreamsReserved int

	// StreamsPending is how many requests have been sent in excess
	// of the peer's advertised MaxConcurrentStreams setting and
	// are waiting for other streams to complete.
	StreamsPending int

	// MaxConcurrentStreams is how many concurrent streams the
	// peer advertised as acceptable. Zero means no SETTINGS
	// frame has been received yet.
	MaxConcurrentStreams uint32

	// LastIdle, if non-zero, is when the connection last
	// transitioned to idle state.
	LastIdle time.Time
}

ClientConnState describes the state of a ClientConn.

type ConnectionError

type ConnectionError ErrCode

ConnectionError is an error that results in the termination of the entire connection.

func (ConnectionError) Error

func (e ConnectionError) Error() string

type ContinuationFrame

type ContinuationFrame struct {
	FrameHeader
	// contains filtered or unexported fields
}

A ContinuationFrame is used to continue a sequence of header block fragments. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.10

func (*ContinuationFrame) HeaderBlockFragment

func (f *ContinuationFrame) HeaderBlockFragment() []byte

func (*ContinuationFrame) HeadersEnded

func (f *ContinuationFrame) HeadersEnded() bool

type DataFrame

type DataFrame struct {
	FrameHeader
	// contains filtered or unexported fields
}

A DataFrame conveys arbitrary, variable-length sequences of octets associated with a stream. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.1

func (*DataFrame) Data

func (f *DataFrame) Data() []byte

Data returns the frame's data octets, not including any padding size byte or padding suffix bytes. The caller must not retain the returned memory past the next call to ReadFrame.

func (*DataFrame) StreamEnded

func (f *DataFrame) StreamEnded() bool

type ErrCode

type ErrCode uint32

An ErrCode is an unsigned 32-bit error code as defined in the HTTP/2 spec.

const (
	ErrCodeNo                 ErrCode = 0x0
	ErrCodeProtocol           ErrCode = 0x1
	ErrCodeInternal           ErrCode = 0x2
	ErrCodeFlowControl        ErrCode = 0x3
	ErrCodeSettingsTimeout    ErrCode = 0x4
	ErrCodeStreamClosed       ErrCode = 0x5
	ErrCodeFrameSize          ErrCode = 0x6
	ErrCodeRefusedStream      ErrCode = 0x7
	ErrCodeCancel             ErrCode = 0x8
	ErrCodeCompression        ErrCode = 0x9
	ErrCodeConnect            ErrCode = 0xa
	ErrCodeEnhanceYourCalm    ErrCode = 0xb
	ErrCodeInadequateSecurity ErrCode = 0xc
	ErrCodeHTTP11Required     ErrCode = 0xd
)

func (ErrCode) String

func (e ErrCode) String() string

type Flags

type Flags uint8

Flags is a bitmask of HTTP/2 flags. The meaning of flags varies depending on the frame type.

const (
	// Data Frame
	FlagDataEndStream Flags = 0x1
	FlagDataPadded    Flags = 0x8

	// Headers Frame
	FlagHeadersEndStream  Flags = 0x1
	FlagHeadersEndHeaders Flags = 0x4
	FlagHeadersPadded     Flags = 0x8
	FlagHeadersPriority   Flags = 0x20

	// Settings Frame
	FlagSettingsAck Flags = 0x1

	// Ping Frame
	FlagPingAck Flags = 0x1

	// Continuation Frame
	FlagContinuationEndHeaders Flags = 0x4

	FlagPushPromiseEndHeaders Flags = 0x4
	FlagPushPromisePadded     Flags = 0x8
)

Frame-specific FrameHeader flag bits.

func (Flags) Has

func (f Flags) Has(v Flags) bool

Has reports whether f contains all (0 or more) flags in v.

type Frame

type Frame interface {
	Header() FrameHeader
	// contains filtered or unexported methods
}

A Frame is the base interface implemented by all frame types. Callers will generally type-assert the specific frame type: *HeadersFrame, *SettingsFrame, *WindowUpdateFrame, etc.

Frames are only valid until the next call to Framer.ReadFrame.

type FrameHeader

type FrameHeader struct {

	// Type is the 1 byte frame type. There are ten standard frame
	// types, but extension frame types may be written by WriteRawFrame
	// and will be returned by ReadFrame (as UnknownFrame).
	Type FrameType

	// Flags are the 1 byte of 8 potential bit flags per frame.
	// They are specific to the frame type.
	Flags Flags

	// Length is the length of the frame, not including the 9 byte header.
	// The maximum size is one byte less than 16MB (uint24), but only
	// frames up to 16KB are allowed without peer agreement.
	Length uint32

	// StreamID is which stream this frame is for. Certain frames
	// are not stream-specific, in which case this field is 0.
	StreamID uint32
	// contains filtered or unexported fields
}

A FrameHeader is the 9 byte header of all HTTP/2 frames.

See https://httpwg.org/specs/rfc7540.html#FrameHeader

func ReadFrameHeader

func ReadFrameHeader(r io.Reader) (FrameHeader, error)

ReadFrameHeader reads 9 bytes from r and returns a FrameHeader. Most users should use Framer.ReadFrame instead.

func (FrameHeader) Header

func (h FrameHeader) Header() FrameHeader

Header returns h. It exists so FrameHeaders can be embedded in other specific frame types and implement the Frame interface.

func (FrameHeader) String

func (h FrameHeader) String() string

type FrameType

type FrameType uint8

A FrameType is a registered frame type as defined in https://httpwg.org/specs/rfc7540.html#rfc.section.11.2

const (
	FrameData         FrameType = 0x0
	FrameHeaders      FrameType = 0x1
	FramePriority     FrameType = 0x2
	FrameRSTStream    FrameType = 0x3
	FrameSettings     FrameType = 0x4
	FramePushPromise  FrameType = 0x5
	FramePing         FrameType = 0x6
	FrameGoAway       FrameType = 0x7
	FrameWindowUpdate FrameType = 0x8
	FrameContinuation FrameType = 0x9
)

func (FrameType) String

func (t FrameType) String() string

type Framer

type Framer struct {

	// AllowIllegalWrites permits the Framer's Write methods to
	// write frames that do not conform to the HTTP/2 spec. This
	// permits using the Framer to test other HTTP/2
	// implementations' conformance to the spec.
	// If false, the Write methods will prefer to return an error
	// rather than comply.
	AllowIllegalWrites bool

	// AllowIllegalReads permits the Framer's ReadFrame method
	// to return non-compliant frames or frame orders.
	// This is for testing and permits using the Framer to test
	// other HTTP/2 implementations' conformance to the spec.
	// It is not compatible with ReadMetaHeaders.
	AllowIllegalReads bool

	// ReadMetaHeaders if non-nil causes ReadFrame to merge
	// HEADERS and CONTINUATION frames together and return
	// MetaHeadersFrame instead.
	ReadMetaHeaders *hpack.Decoder

	// MaxHeaderListSize is the http2 MAX_HEADER_LIST_SIZE.
	// It's used only if ReadMetaHeaders is set; 0 means a sane default
	// (currently 16MB)
	// If the limit is hit, MetaHeadersFrame.Truncated is set true.
	MaxHeaderListSize uint32
	// contains filtered or unexported fields
}

A Framer reads and writes Frames.

func NewFramer

func NewFramer(w io.Writer, r io.Reader) *Framer

NewFramer returns a Framer that writes frames to w and reads them from r.

func (*Framer) ErrorDetail

func (h2f *Framer) ErrorDetail() error

ErrorDetail returns a more detailed error of the last error returned by Framer.ReadFrame. For instance, if ReadFrame returns a StreamError with code PROTOCOL_ERROR, ErrorDetail will say exactly what was invalid. ErrorDetail is not guaranteed to return a non-nil value and like the rest of the http2 package, its return value is not protected by an API compatibility promise. ErrorDetail is reset after the next call to ReadFrame.

func (*Framer) ReadFrame

func (h2f *Framer) ReadFrame() (Frame, error)

ReadFrame reads a single frame. The returned Frame is only valid until the next call to ReadFrame.

If the frame is larger than previously set with SetMaxReadFrameSize, the returned error is errFrameTooLarge. Other errors may be of type ConnectionError, StreamError, or anything else from the underlying reader.

func (*Framer) SetMaxReadFrameSize

func (h2f *Framer) SetMaxReadFrameSize(v uint32)

SetMaxReadFrameSize sets the maximum size of a frame that will be read by a subsequent call to ReadFrame. It is the caller's responsibility to advertise this limit with a SETTINGS frame.

func (*Framer) SetReuseFrames

func (h2f *Framer) SetReuseFrames()

SetReuseFrames allows the Framer to reuse Frames. If called on a Framer, Frames returned by calls to ReadFrame are only valid until the next call to ReadFrame.

func (*Framer) WriteContinuation

func (h2f *Framer) WriteContinuation(streamID uint32, endHeaders bool, headerBlockFragment []byte) error

WriteContinuation writes a CONTINUATION frame.

It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.

func (*Framer) WriteData

func (h2f *Framer) WriteData(streamID uint32, endStream bool, data []byte) error

writeData writes a DATA frame.

It will perform exactly one Write to the underlying Writer. It is the caller's responsibility not to violate the maximum frame size and to not call other Write methods concurrently.

func (*Framer) WriteDataPadded

func (h2f *Framer) WriteDataPadded(streamID uint32, endStream bool, data, pad []byte) error

WriteDataPadded writes a DATA frame with optional padding.

If pad is nil, the padding bit is not sent. The length of pad must not exceed 255 bytes. The bytes of pad must all be zero, unless f.AllowIllegalWrites is set.

It will perform exactly one Write to the underlying Writer. It is the caller's responsibility not to violate the maximum frame size and to not call other Write methods concurrently.

func (*Framer) WriteGoAway

func (h2f *Framer) WriteGoAway(maxStreamID uint32, code ErrCode, debugData []byte) error

func (*Framer) WriteHeaders

func (h2f *Framer) WriteHeaders(p HeadersFrameParam) error

WriteHeaders writes a single HEADERS frame.

This is a low-level header writing method. Encoding headers and splitting them into any necessary CONTINUATION frames is handled elsewhere.

It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.

func (*Framer) WritePing

func (h2f *Framer) WritePing(ack bool, data [8]byte) error

func (*Framer) WritePriority

func (h2f *Framer) WritePriority(streamID uint32, p PriorityParam) error

WritePriority writes a PRIORITY frame.

It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.

func (*Framer) WritePushPromise

func (h2f *Framer) WritePushPromise(p PushPromiseParam) error

WritePushPromise writes a single PushPromise Frame.

As with Header Frames, This is the low level call for writing individual frames. Continuation frames are handled elsewhere.

It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.

func (*Framer) WriteRSTStream

func (h2f *Framer) WriteRSTStream(streamID uint32, code ErrCode) error

WriteRSTStream writes a RST_STREAM frame.

It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.

func (*Framer) WriteRawFrame

func (h2f *Framer) WriteRawFrame(t FrameType, flags Flags, streamID uint32, payload []byte) error

WriteRawFrame writes a raw frame. This can be used to write extension frames unknown to this package.

func (*Framer) WriteSettings

func (h2f *Framer) WriteSettings(settings ...Setting) error

WriteSettings writes a SETTINGS frame with zero or more settings specified and the ACK bit not set.

It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.

func (*Framer) WriteSettingsAck

func (h2f *Framer) WriteSettingsAck() error

WriteSettingsAck writes an empty SETTINGS frame with the ACK bit set.

It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.

func (*Framer) WriteWindowUpdate

func (h2f *Framer) WriteWindowUpdate(streamID, incr uint32) error

WriteWindowUpdate writes a WINDOW_UPDATE frame. The increment value must be between 1 and 2,147,483,647, inclusive. If the Stream ID is zero, the window update applies to the connection as a whole.

type GoAwayError

type GoAwayError struct {
	LastStreamID uint32
	ErrCode      ErrCode
	DebugData    string
}

GoAwayError is returned by the Transport when the server closes the TCP connection after sending a GOAWAY frame.

func (GoAwayError) Error

func (e GoAwayError) Error() string

type GoAwayFrame

type GoAwayFrame struct {
	FrameHeader
	LastStreamID uint32
	ErrCode      ErrCode
	// contains filtered or unexported fields
}

A GoAwayFrame informs the remote peer to stop creating streams on this connection. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.8

func (*GoAwayFrame) DebugData

func (f *GoAwayFrame) DebugData() []byte

DebugData returns any debug data in the GOAWAY frame. Its contents are not defined. The caller must not retain the returned memory past the next call to ReadFrame.

type GzipReader

type GzipReader struct {
	Body io.ReadCloser // underlying Response.Body
	// contains filtered or unexported fields
}

GzipReader wraps a response body so it can lazily call gzip.NewReader on the first call to Read

func (*GzipReader) Close

func (gz *GzipReader) Close() error

func (*GzipReader) Read

func (gz *GzipReader) Read(p []byte) (n int, err error)

type HeadersFrame

type HeadersFrame struct {
	FrameHeader

	// Priority is set if FlagHeadersPriority is set in the FrameHeader.
	Priority PriorityParam
	// contains filtered or unexported fields
}

A HeadersFrame is used to open a stream and additionally carries a header block fragment.

func (*HeadersFrame) HasPriority

func (f *HeadersFrame) HasPriority() bool

func (*HeadersFrame) HeaderBlockFragment

func (f *HeadersFrame) HeaderBlockFragment() []byte

func (*HeadersFrame) HeadersEnded

func (f *HeadersFrame) HeadersEnded() bool

func (*HeadersFrame) StreamEnded

func (f *HeadersFrame) StreamEnded() bool

type HeadersFrameParam

type HeadersFrameParam struct {
	// StreamID is the required Stream ID to initiate.
	StreamID uint32
	// BlockFragment is part (or all) of a Header Block.
	BlockFragment []byte

	// EndStream indicates that the header block is the last that
	// the endpoint will send for the identified stream. Setting
	// this flag causes the stream to enter one of "half closed"
	// states.
	EndStream bool

	// EndHeaders indicates that this frame contains an entire
	// header block and is not followed by any
	// CONTINUATION frames.
	EndHeaders bool

	// PadLength is the optional number of bytes of zeros to add
	// to this frame.
	PadLength uint8

	// Priority, if non-zero, includes stream priority information
	// in the HEADER frame.
	Priority PriorityParam
}

HeadersFrameParam are the parameters for writing a HEADERS frame.

type MetaHeadersFrame

type MetaHeadersFrame struct {
	*HeadersFrame

	// Fields are the fields contained in the HEADERS and
	// CONTINUATION frames. The underlying slice is owned by the
	// Framer and must not be retained after the next call to
	// ReadFrame.
	//
	// Fields are guaranteed to be in the correct http2 order and
	// not have unknown pseudo header fields or invalid header
	// field names or values. Required pseudo header fields may be
	// missing, however. Use the MetaHeadersFrame.Pseudo accessor
	// method access pseudo headers.
	Fields []hpack.HeaderField

	// Truncated is whether the max header list size limit was hit
	// and Fields is incomplete. The hpack decoder state is still
	// valid, however.
	Truncated bool
}

A MetaHeadersFrame is the representation of one HEADERS frame and zero or more contiguous CONTINUATION frames and the decoding of their HPACK-encoded contents.

This type of frame does not appear on the wire and is only returned by the Framer when Framer.ReadMetaHeaders is set.

func (*MetaHeadersFrame) PseudoFields

func (mh *MetaHeadersFrame) PseudoFields() []hpack.HeaderField

PseudoFields returns the pseudo header fields of mh. The caller does not own the returned slice.

func (*MetaHeadersFrame) PseudoValue

func (mh *MetaHeadersFrame) PseudoValue(pseudo string) string

PseudoValue returns the given pseudo header field's value. The provided pseudo field should not contain the leading colon.

func (*MetaHeadersFrame) RegularFields

func (mh *MetaHeadersFrame) RegularFields() []hpack.HeaderField

RegularFields returns the regular (non-pseudo) header fields of mh. The caller does not own the returned slice.

type PingFrame

type PingFrame struct {
	FrameHeader
	Data [8]byte
}

A PingFrame is a mechanism for measuring a minimal round trip time from the sender, as well as determining whether an idle connection is still functional. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.7

func (*PingFrame) IsAck

func (f *PingFrame) IsAck() bool

type PriorityFrame

type PriorityFrame struct {
	FrameHeader
	PriorityParam
}

A PriorityFrame specifies the sender-advised priority of a stream. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.3

type PriorityParam

type PriorityParam struct {
	// StreamDep is a 31-bit stream identifier for the
	// stream that this stream depends on. Zero means no
	// dependency.
	StreamDep uint32

	// Exclusive is whether the dependency is exclusive.
	Exclusive bool

	// Weight is the stream's zero-indexed weight. It should be
	// set together with StreamDep, or neither should be set. Per
	// the spec, "Add one to the value to obtain a weight between
	// 1 and 256."
	Weight uint8
}

PriorityParam are the stream prioritzation parameters.

func (PriorityParam) IsZero

func (p PriorityParam) IsZero() bool

type PushPromiseFrame

type PushPromiseFrame struct {
	FrameHeader
	PromiseID uint32
	// contains filtered or unexported fields
}

A PushPromiseFrame is used to initiate a server stream. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.6

func (*PushPromiseFrame) HeaderBlockFragment

func (f *PushPromiseFrame) HeaderBlockFragment() []byte

func (*PushPromiseFrame) HeadersEnded

func (f *PushPromiseFrame) HeadersEnded() bool

type PushPromiseParam

type PushPromiseParam struct {
	// StreamID is the required Stream ID to initiate.
	StreamID uint32

	// PromiseID is the required Stream ID which this
	// Push Promises
	PromiseID uint32

	// BlockFragment is part (or all) of a Header Block.
	BlockFragment []byte

	// EndHeaders indicates that this frame contains an entire
	// header block and is not followed by any
	// CONTINUATION frames.
	EndHeaders bool

	// PadLength is the optional number of bytes of zeros to add
	// to this frame.
	PadLength uint8
}

PushPromiseParam are the parameters for writing a PUSH_PROMISE frame.

type RSTStreamFrame

type RSTStreamFrame struct {
	FrameHeader
	ErrCode ErrCode
}

A RSTStreamFrame allows for abnormal termination of a stream. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.4

type RoundTripOpt

type RoundTripOpt struct {
	// OnlyCachedConn controls whether RoundTripOpt may
	// create a new TCP 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 Setting

type Setting struct {
	// ID is which setting is being set.
	// See https://httpwg.org/specs/rfc7540.html#SettingValues
	ID SettingID

	// Val is the value.
	Val uint32
}

Setting is a setting parameter: which setting it is, and its value.

func (Setting) String

func (s Setting) String() string

func (Setting) Valid

func (s Setting) Valid() error

Valid reports whether the setting is valid.

type SettingID

type SettingID uint16

A SettingID is an HTTP/2 setting as defined in https://httpwg.org/specs/rfc7540.html#iana-settings

const (
	SettingHeaderTableSize      SettingID = 0x1
	SettingEnablePush           SettingID = 0x2
	SettingMaxConcurrentStreams SettingID = 0x3
	SettingInitialWindowSize    SettingID = 0x4
	SettingMaxFrameSize         SettingID = 0x5
	SettingMaxHeaderListSize    SettingID = 0x6
)

func (SettingID) String

func (s SettingID) String() string

type SettingsFrame

type SettingsFrame struct {
	FrameHeader
	// contains filtered or unexported fields
}

A SettingsFrame conveys configuration parameters that affect how endpoints communicate, such as preferences and constraints on peer behavior.

See https://httpwg.org/specs/rfc7540.html#SETTINGS

func (*SettingsFrame) ForeachSetting

func (f *SettingsFrame) ForeachSetting(fn func(Setting) error) error

ForeachSetting runs fn for each setting. It stops and returns the first error.

func (*SettingsFrame) HasDuplicates

func (f *SettingsFrame) HasDuplicates() bool

HasDuplicates reports whether f contains any duplicate setting IDs.

func (*SettingsFrame) IsAck

func (f *SettingsFrame) IsAck() bool

func (*SettingsFrame) NumSettings

func (f *SettingsFrame) NumSettings() int

func (*SettingsFrame) Setting

func (f *SettingsFrame) Setting(i int) Setting

Setting returns the setting from the frame at the given 0-based index. The index must be >= 0 and less than f.NumSettings().

func (*SettingsFrame) Value

func (f *SettingsFrame) Value(id SettingID) (v uint32, ok bool)

type StreamError

type StreamError struct {
	StreamID uint32
	Code     ErrCode
	Cause    error // optional additional detail
}

StreamError is an error that only affects one stream within an HTTP/2 connection.

func (StreamError) Error

func (e StreamError) Error() string

type Transport

type Transport struct {
	*transport.Options

	// DialTLS specifies an optional dial function for creating
	// TLS connections for requests.
	//
	// If DialTLS is nil, tls.Dial is used.
	//
	// If the returned net.Conn has a ConnectionState method like tls.Conn,
	// it will be used to set http.Response.TLS.
	DialTLS func(network, addr string, cfg *tls.Config) (net.Conn, error)

	// ConnPool optionally specifies an alternate connection pool to use.
	// If nil, the default is used.
	ConnPool ClientConnPool

	// AllowHTTP, if true, permits HTTP/2 requests using the insecure,
	// plain-text "http" scheme. Note that this does not enable h2c support.
	AllowHTTP bool

	// MaxHeaderListSize is the http2 SETTINGS_MAX_HEADER_LIST_SIZE to
	// send in the initial settings frame. It is how many bytes
	// of response headers are allowed. Unlike the http2 spec, zero here
	// means to use a default limit (currently 10MB). If you actually
	// want to advertise an unlimited value to the peer, Transport
	// interprets the highest possible value here (0xffffffff or 1<<32-1)
	// to mean no limit.
	MaxHeaderListSize uint32

	// StrictMaxConcurrentStreams controls whether the server's
	// SETTINGS_MAX_CONCURRENT_STREAMS should be respected
	// globally. If false, new TCP connections are created to the
	// server as needed to keep each under the per-connection
	// SETTINGS_MAX_CONCURRENT_STREAMS limit. If true, the
	// server's SETTINGS_MAX_CONCURRENT_STREAMS is interpreted as
	// a global limit and callers of RoundTrip block when needed,
	// waiting for their turn.
	StrictMaxConcurrentStreams bool

	// ReadIdleTimeout is the timeout after which a health check using ping
	// frame will be carried out if no frame is received on the connection.
	// Note that a ping response will is considered a received frame, so if
	// there is no other traffic on the connection, the health check will
	// be performed every ReadIdleTimeout interval.
	// If zero, no health check is performed.
	ReadIdleTimeout time.Duration

	// PingTimeout is the timeout after which the connection will be closed
	// if a response to Ping is not received.
	// Defaults to 15s.
	PingTimeout time.Duration

	// WriteByteTimeout is the timeout after which the connection will be
	// closed no data can be written to it. The timeout begins when data is
	// available to write, and is extended whenever any bytes are written.
	WriteByteTimeout time.Duration

	// CountError, if non-nil, is called on HTTP/2 transport errors.
	// It's intended to increment a metric for monitoring, such
	// as an expvar or Prometheus metric.
	// The errType consists of only ASCII word characters.
	CountError func(errType string)
	// contains filtered or unexported fields
}

Transport is an HTTP/2 Transport.

A Transport internally caches connections to servers. It is safe for concurrent use by multiple goroutines.

func (*Transport) AddConn

func (t *Transport) AddConn(conn net.Conn, addr string) (used bool, err error)

func (*Transport) CloseIdleConnections

func (t *Transport) CloseIdleConnections()

CloseIdleConnections closes any connections which were previously connected from previous requests but are now sitting idle. It does not interrupt any connections currently in use.

func (*Transport) NewClientConn

func (t *Transport) NewClientConn(c net.Conn) (*ClientConn, error)

func (*Transport) RoundTrip

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

func (*Transport) RoundTripOnlyCachedConn

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

func (*Transport) RoundTripOpt

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

RoundTripOpt is like RoundTrip, but takes options.

type UnknownFrame

type UnknownFrame struct {
	FrameHeader
	// contains filtered or unexported fields
}

An UnknownFrame is the frame type returned when the frame type is unknown or no specific frame type parser exists.

func (*UnknownFrame) Payload

func (f *UnknownFrame) Payload() []byte

Payload returns the frame's payload (after the header). It is not valid to call this method after a subsequent call to Framer.ReadFrame, nor is it valid to retain the returned slice. The memory is owned by the Framer and is invalidated when the next frame is read.

type WindowUpdateFrame

type WindowUpdateFrame struct {
	FrameHeader
	Increment uint32 // never read with high bit set
}

A WindowUpdateFrame is used to implement flow control. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.9

Jump to

Keyboard shortcuts

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