package http2
Import Path
net/http/internal/http2 (on go.dev)
Dependency Relation
imports 36 packages, and imported by one package
Involved Source Files
api.go
ascii.go
ciphers.go
client_conn_pool.go
config.go
databuffer.go
errors.go
flow.go
frame.go
gotrack.go
Package http2 implements the HTTP/2 protocol.
This package is low-level and intended to be used directly by very
few people. Most users will use it indirectly through the automatic
use by the net/http package (from Go 1.6 and later).
For use in earlier Go versions see ConfigureServer. (Transport support
requires Go 1.6 or later)
See https://http2.github.io/ for more information on HTTP/2.
pipe.go
server.go
transport.go
write.go
writesched.go
writesched_priority_rfc9218.go
writesched_roundrobin.go
Package-Level Type Names (total 48)
ClientConn is the state of a single HTTP/2 client connection to an
HTTP/2 server.
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.
Close closes the client connection immediately.
In-flight requests are interrupted. For a graceful shutdown, use Shutdown instead.
Ping sends a PING frame to the server and waits for the ack.
ReserveNewRequest is like CanTakeNewRequest but also reserves a
concurrent stream in cc. The reservation is decremented on the
next call to RoundTrip.
(*ClientConn) RoundTrip(req *ClientRequest) (*ClientResponse, error)
SetDoNotReuse marks cc as not reusable for future HTTP requests.
Shutdown gracefully closes the client connection, waiting for running streams to complete.
State returns a snapshot of cc's state.
*ClientConn : database/sql/driver.Pinger
*ClientConn : github.com/prometheus/common/expfmt.Closer
*ClientConn : io.Closer
ClientConnState describes the state of a ClientConn.
Closed is whether the connection is closed.
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.
LastIdle, if non-zero, is when the connection last
transitioned to idle state.
MaxConcurrentStreams is how many concurrent streams the
peer advertised as acceptable. Zero means no SETTINGS
frame has been received yet.
StreamsActive is how many streams are active.
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.
StreamsReserved is how many streams have been reserved via
ClientConn.ReserveNewRequest.
func (*ClientConn).State() ClientConnState
A ClientRequest is a Request used by the HTTP/2 client (Transport).
Body io.ReadCloser
Cancel <-chan struct{}
Close bool
ContentLength int64
Context context.Context
GetBody func() (io.ReadCloser, error)
Header Header
Host string
Method string
ResTrailer *Header
Trailer Header
URL *url.URL
Clone makes a shallow copy of ClientRequest.
Clone is only used in shouldRetryRequest.
We can drop it if we ever get rid of or rework that function.
func (*ClientRequest).Clone() *ClientRequest
func (*ClientConn).RoundTrip(req *ClientRequest) (*ClientResponse, error)
func NetHTTPClientConn.RoundTrip(req *ClientRequest) (*ClientResponse, error)
func (*Transport).RoundTrip(req *ClientRequest) (*ClientResponse, error)
func (*Transport).RoundTripOpt(req *ClientRequest, opt RoundTripOpt) (*ClientResponse, error)
A ClientResponse is a Request used by the HTTP/2 client (Transport).
Body io.ReadCloser
ContentLength int64
Header Header
// e.g. "200"
// e.g. 200
TLS *tls.ConnectionState
Trailer Header
Uncompressed bool
func (*ClientConn).RoundTrip(req *ClientRequest) (*ClientResponse, error)
func NetHTTPClientConn.RoundTrip(req *ClientRequest) (*ClientResponse, error)
func (*Transport).RoundTrip(req *ClientRequest) (*ClientResponse, error)
func (*Transport).RoundTripOpt(req *ClientRequest, opt RoundTripOpt) (*ClientResponse, error)
Config must be kept in sync with net/http.HTTP2Config.
CountError func(errType string)
MaxConcurrentStreams int
MaxDecoderHeaderTableSize int
MaxEncoderHeaderTableSize int
MaxReadFrameSize int
MaxReceiveBufferPerConnection int
MaxReceiveBufferPerStream int
PermitProhibitedCipherSuites bool
PingTimeout time.Duration
SendPingTimeout time.Duration
StrictMaxConcurrentRequests bool
WriteByteTimeout time.Duration
func ServerConfig.HTTP2Config() Config
func TransportConfig.HTTP2Config() Config
ConnectionError is an error that results in the termination of the
entire connection.
( ConnectionError) Error() string
ConnectionError : error
ConnState is identical to net/http.ConnState.
func ServerConfig.ConnState(net.Conn, ConnState)
const ConnStateActive
const ConnStateClosed
const ConnStateHijacked
const ConnStateIdle
const ConnStateNew
A ContinuationFrame is used to continue a sequence of header block fragments.
See https://httpwg.org/specs/rfc7540.html#rfc.section.6.10
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
(*ContinuationFrame) HeaderBlockFragment() []byte
(*ContinuationFrame) HeadersEnded() bool
( ContinuationFrame) String() string
*ContinuationFrame : Frame
ContinuationFrame : expvar.Var
ContinuationFrame : fmt.Stringer
A DataFrame conveys arbitrary, variable-length sequences of octets
associated with a stream.
See https://httpwg.org/specs/rfc7540.html#rfc.section.6.1
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
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.
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
(*DataFrame) StreamEnded() bool
( DataFrame) String() string
*DataFrame : Frame
DataFrame : expvar.Var
DataFrame : fmt.Stringer
An ErrCode is an unsigned 32-bit error code as defined in the HTTP/2 spec.
( ErrCode) String() string
ErrCode : expvar.Var
ErrCode : fmt.Stringer
func (*Framer).WriteGoAway(maxStreamID uint32, code ErrCode, debugData []byte) error
func (*Framer).WriteRSTStream(streamID uint32, code ErrCode) error
const ErrCodeCancel
const ErrCodeCompression
const ErrCodeConnect
const ErrCodeEnhanceYourCalm
const ErrCodeFlowControl
const ErrCodeFrameSize
const ErrCodeHTTP11Required
const ErrCodeInadequateSecurity
const ErrCodeInternal
const ErrCodeNo
const ErrCodeProtocol
const ErrCodeRefusedStream
const ErrCodeSettingsTimeout
const ErrCodeStreamClosed
Flags is a bitmask of HTTP/2 flags.
The meaning of flags varies depending on the frame type.
Has reports whether f contains all (0 or more) flags in v.
func Flags.Has(v Flags) bool
func (*Framer).WriteRawFrame(t FrameType, flags Flags, streamID uint32, payload []byte) error
const FlagContinuationEndHeaders
const FlagDataEndStream
const FlagDataPadded
const FlagHeadersEndHeaders
const FlagHeadersEndStream
const FlagHeadersPadded
const FlagHeadersPriority
const FlagPingAck
const FlagPushPromiseEndHeaders
const FlagPushPromisePadded
const FlagSettingsAck
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.
( Frame) Header() FrameHeader
*ContinuationFrame
*DataFrame
*FrameHeader
*GoAwayFrame
*HeadersFrame
MetaHeadersFrame
*PingFrame
*PriorityFrame
*PriorityUpdateFrame
*PushPromiseFrame
*RSTStreamFrame
*SettingsFrame
*UnknownFrame
*WindowUpdateFrame
func (*Framer).ReadFrame() (Frame, error)
func (*Framer).ReadFrameForHeader(fh FrameHeader) (Frame, error)
A FrameHeader is the 9 byte header of all HTTP/2 frames.
See https://httpwg.org/specs/rfc7540.html#FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
( FrameHeader) String() string
*FrameHeader : Frame
FrameHeader : expvar.Var
FrameHeader : fmt.Stringer
func ReadFrameHeader(r io.Reader) (FrameHeader, error)
func Frame.Header() FrameHeader
func FrameHeader.Header() FrameHeader
func (*Framer).ReadFrameHeader() (FrameHeader, error)
func (*Framer).ReadFrameForHeader(fh FrameHeader) (Frame, error)
A Framer reads and writes Frames.
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.
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.
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.
MaxHeaderValueCount is the maximum permitted number of
header values.
It's used only if ReadMetaHeaders is set; 0 means no limit.
If the limit is hit, MetaHeadersFrame.Truncated is set true.
ReadMetaHeaders if non-nil causes ReadFrame to merge
HEADERS and CONTINUATION frames together and return
MetaHeadersFrame instead.
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.
ReadFrame reads a single frame. The returned Frame is only valid
until the next call to ReadFrame or ReadFrameBodyForHeader.
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.
If ReadFrame returns an error and a non-nil Frame, the Frame's StreamID
indicates the stream responsible for the error.
ReadFrameForHeader reads the payload for the frame with the given FrameHeader.
It behaves identically to ReadFrame, other than not checking the maximum
frame size.
ReadFrameHeader reads the header of the next frame.
It reads the 9-byte fixed frame header, and does not read any portion of the
frame payload. The caller is responsible for consuming the payload, either
with ReadFrameForHeader or directly from the Framer's io.Reader.
If the frame is larger than previously set with SetMaxReadFrameSize, it
returns the frame header and ErrFrameTooLarge.
If the returned FrameHeader.StreamID is non-zero, it indicates the stream
responsible for the error.
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.
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.
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.
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.
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.
(*Framer) WriteGoAway(maxStreamID uint32, code ErrCode, debugData []byte) 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.
(*Framer) WritePing(ack bool, data [8]byte) 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.
WritePriorityUpdate writes a PRIORITY_UPDATE frame.
It will perform exactly one Write to the underlying Writer.
It is the caller's responsibility to not call other Write methods concurrently.
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.
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.
WriteRawFrame writes a raw frame. This can be used to write
extension frames unknown to this package.
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.
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.
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.
func NewFramer(w io.Writer, r io.Reader) *Framer
A FrameType is a registered frame type as defined in
https://httpwg.org/specs/rfc7540.html#rfc.section.11.2 and other future
RFCs.
( FrameType) String() string
FrameType : expvar.Var
FrameType : fmt.Stringer
func (*Framer).WriteRawFrame(t FrameType, flags Flags, streamID uint32, payload []byte) error
const FrameContinuation
const FrameData
const FrameGoAway
const FrameHeaders
const FramePing
const FramePriority
const FramePriorityUpdate
const FramePushPromise
const FrameRSTStream
const FrameSettings
const FrameWindowUpdate
FrameWriteRequest is a request to write a frame.
Consume consumes min(n, available) bytes from this frame, where available
is the number of flow control bytes available on the stream. Consume returns
0, 1, or 2 frames, where the integer return value gives the number of frames
returned.
If flow control prevents consuming any bytes, this returns (_, _, 0). If
the entire frame was consumed, this returns (wr, _, 1). Otherwise, this
returns (consumed, rest, 2), where 'consumed' contains the consumed bytes and
'rest' contains the remaining bytes. The consumed bytes are deducted from the
underlying stream's flow control budget.
DataSize returns the number of flow control bytes that must be consumed
to write this entire frame. This is 0 for non-DATA frames.
StreamID returns the id of the stream this frame will be written to.
0 is used for non-stream frames such as PING and SETTINGS.
String is for debugging only.
FrameWriteRequest : expvar.Var
FrameWriteRequest : fmt.Stringer
func FrameWriteRequest.Consume(n int32) (FrameWriteRequest, FrameWriteRequest, int)
func FrameWriteRequest.Consume(n int32) (FrameWriteRequest, FrameWriteRequest, int)
func WriteScheduler.Pop() (wr FrameWriteRequest, ok bool)
func WriteScheduler.Push(wr FrameWriteRequest)
GoAwayError is returned by the Transport when the server closes the
TCP connection after sending a GOAWAY frame.
DebugData string
ErrCode ErrCode
LastStreamID uint32
( GoAwayError) Error() string
GoAwayError : error
A GoAwayFrame informs the remote peer to stop creating streams on this connection.
See https://httpwg.org/specs/rfc7540.html#rfc.section.6.8
ErrCode ErrCode
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
LastStreamID uint32
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.
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
( GoAwayFrame) String() string
*GoAwayFrame : Frame
GoAwayFrame : expvar.Var
GoAwayFrame : fmt.Stringer
( Handler) ServeHTTP(*ResponseWriter, *ServerRequest)
type Header = textproto.MIMEHeader (map)
A HeadersFrame is used to open a stream and additionally carries a
header block fragment.
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
Priority is set if FlagHeadersPriority is set in the FrameHeader.
(*HeadersFrame) HasPriority() bool
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
(*HeadersFrame) HeaderBlockFragment() []byte
(*HeadersFrame) HeadersEnded() bool
(*HeadersFrame) StreamEnded() bool
( HeadersFrame) String() string
*HeadersFrame : Frame
HeadersFrame : expvar.Var
HeadersFrame : fmt.Stringer
HeadersFrameParam are the parameters for writing a HEADERS frame.
BlockFragment is part (or all) of a Header Block.
EndHeaders indicates that this frame contains an entire
header block and is not followed by any
CONTINUATION frames.
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.
PadLength is the optional number of bytes of zeros to add
to this frame.
Priority, if non-zero, includes stream priority information
in the HEADER frame.
StreamID is the required Stream ID to initiate.
func (*Framer).WriteHeaders(p HeadersFrameParam) error
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.
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.
HeadersFrame *HeadersFrame
HeadersFrame.FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
Priority is set if FlagHeadersPriority is set in the FrameHeader.
Truncated is whether the max header list size limit was hit
and Fields is incomplete. The hpack decoder state is still
valid, however.
( MetaHeadersFrame) HasPriority() bool
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
( MetaHeadersFrame) HeaderBlockFragment() []byte
( MetaHeadersFrame) HeadersEnded() bool
PseudoFields returns the pseudo header fields of mh.
The caller does not own the returned slice.
PseudoValue returns the given pseudo header field's value.
The provided pseudo field should not contain the leading colon.
RegularFields returns the regular (non-pseudo) header fields of mh.
The caller does not own the returned slice.
( MetaHeadersFrame) StreamEnded() bool
( MetaHeadersFrame) String() string
MetaHeadersFrame : Frame
MetaHeadersFrame : expvar.Var
MetaHeadersFrame : fmt.Stringer
netHTTPClientConn wraps ClientConn and implements the interface net/http expects from
the RoundTripper returned by NewClientConn.
( NetHTTPClientConn) Available() int
( NetHTTPClientConn) Close() error
( NetHTTPClientConn) Err() error
( NetHTTPClientConn) InFlight() int
( NetHTTPClientConn) Ping(ctx context.Context) error
( NetHTTPClientConn) Release()
( NetHTTPClientConn) Reserve() error
( NetHTTPClientConn) RoundTrip(req *ClientRequest) (*ClientResponse, error)
NetHTTPClientConn : database/sql/driver.Pinger
NetHTTPClientConn : github.com/prometheus/common/expfmt.Closer
NetHTTPClientConn : io.Closer
func (*Transport).NewClientConn(c net.Conn, internalStateHook func()) (NetHTTPClientConn, error)
OpenStreamOptions specifies extra options for WriteScheduler.OpenStream.
PusherID is zero if the stream was initiated by the client. Otherwise,
PusherID names the stream that pushed the newly opened stream.
func WriteScheduler.OpenStream(streamID uint32, options OpenStreamOptions)
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
Data [8]byte
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
(*PingFrame) IsAck() bool
( PingFrame) String() string
*PingFrame : Frame
PingFrame : expvar.Var
PingFrame : fmt.Stringer
A PriorityFrame specifies the sender-advised priority of a stream.
See https://httpwg.org/specs/rfc7540.html#rfc.section.6.3
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
PriorityParam PriorityParam
Exclusive is whether the dependency is exclusive.
StreamDep is a 31-bit stream identifier for the
stream that this stream depends on. Zero means no
dependency.
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."
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
( PriorityFrame) IsZero() bool
( PriorityFrame) String() string
*PriorityFrame : Frame
PriorityFrame : expvar.Var
PriorityFrame : fmt.Stringer
PriorityFrame : go.yaml.in/yaml/v3.IsZeroer
PriorityFrame : gopkg.in/yaml.v3.IsZeroer
PriorityParam are the stream prioritization parameters.
Exclusive is whether the dependency is exclusive.
StreamDep is a 31-bit stream identifier for the
stream that this stream depends on. Zero means no
dependency.
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."
( PriorityParam) IsZero() bool
PriorityParam : go.yaml.in/yaml/v3.IsZeroer
PriorityParam : gopkg.in/yaml.v3.IsZeroer
func (*Framer).WritePriority(streamID uint32, p PriorityParam) error
func WriteScheduler.AdjustStream(streamID uint32, priority PriorityParam)
PriorityUpdateFrame is a PRIORITY_UPDATE frame as described in
https://www.rfc-editor.org/rfc/rfc9218.html#name-the-priority_update-frame.
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
PrioritizedStreamID uint32
Priority string
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
( PriorityUpdateFrame) String() string
*PriorityUpdateFrame : Frame
PriorityUpdateFrame : expvar.Var
PriorityUpdateFrame : fmt.Stringer
A PushPromiseFrame is used to initiate a server stream.
See https://httpwg.org/specs/rfc7540.html#rfc.section.6.6
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
PromiseID uint32
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
(*PushPromiseFrame) HeaderBlockFragment() []byte
(*PushPromiseFrame) HeadersEnded() bool
( PushPromiseFrame) String() string
*PushPromiseFrame : Frame
PushPromiseFrame : expvar.Var
PushPromiseFrame : fmt.Stringer
PushPromiseParam are the parameters for writing a PUSH_PROMISE frame.
BlockFragment is part (or all) of a Header Block.
EndHeaders indicates that this frame contains an entire
header block and is not followed by any
CONTINUATION frames.
PadLength is the optional number of bytes of zeros to add
to this frame.
PromiseID is the required Stream ID which this
Push Promises
StreamID is the required Stream ID to initiate.
func (*Framer).WritePushPromise(p PushPromiseParam) error
(*ResponseWriter) CloseNotify() <-chan bool
(*ResponseWriter) EnableFullDuplex() error
(*ResponseWriter) Flush()
(*ResponseWriter) FlushError() error
(*ResponseWriter) Header() Header
(*ResponseWriter) Push(target, method string, header Header) error
(*ResponseWriter) SetReadDeadline(deadline time.Time) error
(*ResponseWriter) SetWriteDeadline(deadline time.Time) error
The Life Of A Write is like this:
* Handler calls w.Write or w.WriteString ->
* -> rws.bw (*bufio.Writer) ->
* (Handler might call Flush)
* -> chunkWriter{rws}
* -> responseWriterState.writeChunk(p []byte)
* -> responseWriterState.writeChunk (most of the magic; see comment there)
(*ResponseWriter) WriteHeader(code int)
(*ResponseWriter) WriteString(s string) (n int, err error)
*ResponseWriter : net/http.CloseNotifier
*ResponseWriter : net/http.Flusher
*ResponseWriter : github.com/miekg/dns.Writer
*ResponseWriter : github.com/pion/datachannel.ReadDeadliner
*ResponseWriter : github.com/pion/datachannel.WriteDeadliner
*ResponseWriter : internal/bisect.Writer
*ResponseWriter : io.StringWriter
*ResponseWriter : io.Writer
RoundTripOpt are options for the Transport.RoundTripOpt method.
OnlyCachedConn controls whether RoundTripOpt may
create a new TCP connection. If set true and
no cached connection is available, RoundTripOpt
will return ErrNoCachedConn.
func (*Transport).RoundTripOpt(req *ClientRequest, opt RoundTripOpt) (*ClientResponse, error)
A RSTStreamFrame allows for abnormal termination of a stream.
See https://httpwg.org/specs/rfc7540.html#rfc.section.6.4
ErrCode ErrCode
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
( RSTStreamFrame) String() string
*RSTStreamFrame : Frame
RSTStreamFrame : expvar.Var
RSTStreamFrame : fmt.Stringer
ServeConnOpts are options for the Server.ServeConn method.
BaseConfig optionally sets the base configuration
for values. If nil, defaults are used.
Context is the base context to use.
If nil, context.Background is used.
Handler specifies which handler to use for processing
requests. If nil, BaseConfig.Handler is used. If BaseConfig
or BaseConfig.Handler is nil, http.DefaultServeMux is used.
SawClientPreface is set if the HTTP/2 connection preface
has already been read from the connection.
Settings is the decoded contents of the HTTP2-Settings header
in an h2c upgrade request.
UpgradeRequest *ServerRequest
func (*Server).ServeConn(c net.Conn, opts *ServeConnOpts)
Server is an HTTP/2 server.
(*Server) Configure(conf ServerConfig, tcfg *tls.Config) error
(*Server) GracefulShutdown()
ServeConn serves HTTP/2 requests on the provided connection and
blocks until the connection is no longer readable.
ServeConn starts speaking HTTP/2 assuming that c has not had any
reads or writes. It writes its initial settings frame and expects
to be able to read the preface and settings frame from the
client. If c has a ConnectionState method like a *tls.Conn, the
ConnectionState is used to verify the TLS ciphersuite and to set
the Request.TLS field in Handlers.
ServeConn does not support h2c by itself. Any h2c support must be
implemented in terms of providing a suitably-behaving net.Conn.
The opts parameter is optional. If nil, default values are used.
ServerConfig is configuration from an http.Server.
( ServerConfig) ConnState(net.Conn, ConnState)
( ServerConfig) DisableClientPriority() bool
( ServerConfig) DoKeepAlives() bool
( ServerConfig) ErrorLog() *log.Logger
( ServerConfig) HTTP2Config() Config
( ServerConfig) IdleTimeout() time.Duration
( ServerConfig) MaxHeaderBytes() int
( ServerConfig) MaxHeaderValueCount() int
( ServerConfig) ReadTimeout() time.Duration
( ServerConfig) SendPingTimeout() time.Duration
( ServerConfig) WriteTimeout() time.Duration
func (*Server).Configure(conf ServerConfig, tcfg *tls.Config) error
A ServerRequest is a Request used by the HTTP/2 server.
Body io.ReadCloser
ContentLength int64
Context context.Context
Header Header
Host string
Method string
MultipartForm *multipart.Form
// e.g. "HTTP/1.0"
// e.g. 1
// e.g. 0
RemoteAddr string
RequestURI string
TLS *tls.ConnectionState
Trailer Header
URL *url.URL
func Handler.ServeHTTP(*ResponseWriter, *ServerRequest)
Setting is a setting parameter: which setting it is, and its value.
ID is which setting is being set.
See https://httpwg.org/specs/rfc7540.html#SettingFormat
Val is the value.
( Setting) String() string
Valid reports whether the setting is valid.
Setting : expvar.Var
Setting : fmt.Stringer
func (*SettingsFrame).Setting(i int) Setting
func (*Framer).WriteSettings(settings ...Setting) error
A SettingID is an HTTP/2 setting as defined in
https://httpwg.org/specs/rfc7540.html#iana-settings
( SettingID) String() string
SettingID : expvar.Var
SettingID : fmt.Stringer
func (*SettingsFrame).Value(id SettingID) (v uint32, ok bool)
const SettingEnableConnectProtocol
const SettingEnablePush
const SettingHeaderTableSize
const SettingInitialWindowSize
const SettingMaxConcurrentStreams
const SettingMaxFrameSize
const SettingMaxHeaderListSize
const SettingNoRFC7540Priorities
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
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
ForeachSetting runs fn for each setting.
It stops and returns the first error.
HasDuplicates reports whether f contains any duplicate setting IDs.
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
(*SettingsFrame) IsAck() bool
(*SettingsFrame) NumSettings() int
Setting returns the setting from the frame at the given 0-based index.
The index must be >= 0 and less than f.NumSettings().
( SettingsFrame) String() string
(*SettingsFrame) Value(id SettingID) (v uint32, ok bool)
*SettingsFrame : Frame
SettingsFrame : expvar.Var
SettingsFrame : fmt.Stringer
StreamError is an error that only affects one stream within an
HTTP/2 connection.
// optional additional detail
Code ErrCode
StreamID uint32
This As function permits converting a StreamError into a x/net/http2.StreamError.
( StreamError) Error() string
StreamError : error
Transport is an HTTP/2 Transport.
A Transport internally caches connections to servers. It is safe
for concurrent use by multiple goroutines.
(*Transport) AddConn(scheme, authority string, c net.Conn) error
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.
(*Transport) IdleConnStrsForTesting() []string
(*Transport) NewClientConn(c net.Conn, internalStateHook func()) (NetHTTPClientConn, error)
(*Transport) RoundTrip(req *ClientRequest) (*ClientResponse, error)
RoundTripOpt is like RoundTrip, but takes options.
func NewTransport(t1 TransportConfig) *Transport
TransportConfig is configuration from an http.Transport.
( TransportConfig) DisableCompression() bool
( TransportConfig) DisableKeepAlives() bool
( TransportConfig) ExpectContinueTimeout() time.Duration
( TransportConfig) HTTP2Config() Config
( TransportConfig) IdleConnTimeout() time.Duration
( TransportConfig) MaxHeaderListSize() int64
( TransportConfig) MaxResponseHeaderBytes() int64
( TransportConfig) ResponseHeaderTimeout() time.Duration
func NewTransport(t1 TransportConfig) *Transport
An UnknownFrame is the frame type returned when the frame type is unknown
or no specific frame type parser exists.
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
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.
( UnknownFrame) String() string
*UnknownFrame : Frame
UnknownFrame : expvar.Var
UnknownFrame : fmt.Stringer
A WindowUpdateFrame is used to implement flow control.
See https://httpwg.org/specs/rfc7540.html#rfc.section.6.9
FrameHeader FrameHeader
Flags are the 1 byte of 8 potential bit flags per frame.
They are specific to the frame type.
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.
StreamID is which stream this frame is for. Certain frames
are not stream-specific, in which case this field is 0.
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).
// never read with high bit set
Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface.
( WindowUpdateFrame) String() string
*WindowUpdateFrame : Frame
WindowUpdateFrame : expvar.Var
WindowUpdateFrame : fmt.Stringer
WriteScheduler is the interface implemented by HTTP/2 write schedulers.
Methods are never called concurrently.
AdjustStream adjusts the priority of the given stream. This may be called
on a stream that has not yet been opened or has been closed. Note that
RFC 7540 allows PRIORITY frames to be sent on streams in any state. See:
https://tools.ietf.org/html/rfc7540#section-5.1
CloseStream closes a stream in the write scheduler. Any frames queued on
this stream should be discarded. It is illegal to call this on a stream
that is not open -- the call may panic.
OpenStream opens a new stream in the write scheduler.
It is illegal to call this with streamID=0 or with a streamID that is
already open -- the call may panic.
Pop dequeues the next frame to write. Returns false if no frames can
be written. Frames with a given wr.StreamID() are Pop'd in the same
order they are Push'd, except RST_STREAM frames. No frames should be
discarded except by CloseStream.
Push queues a frame in the scheduler. In most cases, this will not be
called with wr.StreamID()!=0 unless that stream is currently open. The one
exception is RST_STREAM frames, which may be sent on idle or closed streams.
Package-Level Functions (total 3)
NewFramer returns a Framer that writes frames to w and reads them from r.
func NewTransport(t1 TransportConfig) *Transport
ReadFrameHeader reads 9 bytes from r and returns a FrameHeader.
Most users should use Framer.ReadFrame instead.
Package-Level Variables (total 14)
var DebugGoroutines bool var ErrAbortHandler error
ErrFrameTooLarge is returned from Framer.ReadFrame when the peer
sends a frame that is larger than declared with SetMaxReadFrameSize.
var ErrNoCachedConn error var ErrNotSupported error
Push errors.
Push errors.
Variables defined in net/http and initialized by an init func in that package.
NoBody and LocalAddrContextKey have concrete types in net/http,
and therefore can't be moved into a common package without introducing
a dependency cycle.
var NewConnContextKey *string
Variables defined in net/http and initialized by an init func in that package.
NoBody and LocalAddrContextKey have concrete types in net/http,
and therefore can't be moved into a common package without introducing
a dependency cycle.
var VerboseLogs bool
Package-Level Constants (total 54)
ClientPreface is the string that must be sent by new
connections from clients.
const ConnStateActive ConnState = 1 const ConnStateClosed ConnState = 4 const ConnStateHijacked ConnState = 3 const ConnStateIdle ConnState = 2 const ConnStateNew ConnState = 0 const DefaultMaxHeaderBytes = 1048576 // keep this in sync with net/http const ErrCodeCancel ErrCode = 8 const ErrCodeCompression ErrCode = 9 const ErrCodeConnect ErrCode = 10 const ErrCodeEnhanceYourCalm ErrCode = 11 const ErrCodeFlowControl ErrCode = 3 const ErrCodeFrameSize ErrCode = 6 const ErrCodeHTTP11Required ErrCode = 13 const ErrCodeInadequateSecurity ErrCode = 12 const ErrCodeInternal ErrCode = 2 const ErrCodeProtocol ErrCode = 1 const ErrCodeRefusedStream ErrCode = 7 const ErrCodeSettingsTimeout ErrCode = 4 const ErrCodeStreamClosed ErrCode = 5
Continuation Frame
Data Frame
Frame-specific FrameHeader flag bits.
Frame-specific FrameHeader flag bits.
Headers Frame
Frame-specific FrameHeader flag bits.
Frame-specific FrameHeader flag bits.
Ping Frame
Frame-specific FrameHeader flag bits.
Frame-specific FrameHeader flag bits.
Settings Frame
const FrameContinuation FrameType = 9 const FrameGoAway FrameType = 7 const FrameHeaders FrameType = 1 const FramePriority FrameType = 2 const FramePriorityUpdate FrameType = 16 const FramePushPromise FrameType = 5 const FrameRSTStream FrameType = 3 const FrameSettings FrameType = 4 const FrameWindowUpdate FrameType = 8
NextProtoTLS is the NPN/ALPN protocol negotiated during
HTTP/2's TLS setup.
const SettingEnableConnectProtocol SettingID = 8 const SettingEnablePush SettingID = 2 const SettingHeaderTableSize SettingID = 1 const SettingInitialWindowSize SettingID = 4 const SettingMaxConcurrentStreams SettingID = 3 const SettingMaxFrameSize SettingID = 5 const SettingMaxHeaderListSize SettingID = 6 const SettingNoRFC7540Priorities SettingID = 9 const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" // keep in sync with net/http
TrailerPrefix is a magic prefix for ResponseWriter.Header map keys
that, if present, signals that the map entry is actually for
the response trailers, and not the response headers. The prefix
is stripped after the ServeHTTP call finishes and the values are
sent in the trailers.
This mechanism is intended only for trailers that are not known
prior to the headers being written. If the set of trailers is fixed
or known before the header is written, the normal Go trailers mechanism
is preferred:
https://golang.org/pkg/net/http/#ResponseWriter
https://golang.org/pkg/net/http/#example_ResponseWriter_trailers
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |