Documentation
¶
Overview ¶
Package http2 is the contract of the SDK's HTTP/2 codec (ADR 0221): the values both engines read — the frame header, the settings, the bounds of ADR 0195 §D3 as a value — and the sentinels and codes its refusals carry, range 0.3.109.*, declared here at the engine's path (ADR 0160). The wire format itself, the frame layer and HPACK, is internal/service/net/http2's. A wire error code (ErrCode) is the protocol's vocabulary and is not an error of the SDK's; a sentinel is what a program branches on.
Index ¶
Constants ¶
const ( // DefaultMaxStreams is how many streams a connection may hold open: a zero // LimitsValue.MaxStreams selects it. DefaultMaxStreams int = 100 // DefaultMaxFrame is the largest frame the codec accepts by default, and the // protocol's minimum: a zero LimitsValue.MaxFrame selects it. DefaultMaxFrame int = 16384 // MaxFrameLimit is the largest frame the protocol can spell, RFC 9113 §4.2. MaxFrameLimit int = 1<<24 - 1 // DefaultHeaderTable is the HPACK dynamic table the server advertises by // default, RFC 7541 §4.2's own size. DefaultHeaderTable int = 4096 // MaxHeaderTable is the largest HEADER_TABLE_SIZE a configuration may ask for: // the table's entries are measured with 16 bits. MaxHeaderTable int = 1<<16 - 1 // NoDynamicTable, as LimitsValue.HeaderTable, advertises a table of size zero: // a zero field is never inert (ADR 0031), so -1 says it. NoDynamicTable int = -1 // DefaultReceivePerStream is the window one stream's body may hold unread. DefaultReceivePerStream int = 256 << 10 // DefaultMaxHeaderList is the header list a request may carry, RFC 9113 §6.5.2's // measure: the bound of http1's head (ADR 0186). DefaultMaxHeaderList int = 8192 // DefaultWindow is the protocol's initial flow-control window, RFC 9113 §6.9.2. DefaultWindow int = 65535 // MaxWindow is the largest flow-control window, RFC 9113 §6.9.1. MaxWindow int = 1<<31 - 1 )
const CodeCompressionFailed errs.Code = 0x00_03_6D_03 // 0.3.109.3
CodeCompressionFailed identifies a field block the connection's HPACK state cannot survive: an index past the tables, a bad integer or string, a size update out of its place or past what the server advertised.
const CodeFieldMalformed errs.Code = 0x00_03_6D_04 // 0.3.109.4
CodeFieldMalformed identifies a decoded field RFC 9113 §8.2.1 calls malformed; the block was decoded to its end, so the connection's HPACK state is intact and only the stream is refused.
const CodeFrameMalformed errs.Code = 0x00_03_6D_01 // 0.3.109.1
CodeFrameMalformed identifies an HTTP/2 frame that breaks the layout RFC 9113 §4 and §6 give it.
const CodeHeadersTooLarge errs.Code = 0x00_03_6D_02 // 0.3.109.2
CodeHeadersTooLarge identifies a field block past the connection's header list ceiling, or holding more fields than a request value has room for.
const CodeLimitsRefused errs.Code = 0x00_03_6D_05 // 0.3.109.5
CodeLimitsRefused identifies a LimitsValue that cannot be honoured.
const ErrorTypes int = 17
ErrorTypes bounds the ErrorType values, the length of a table indexed by one.
const FrameHeaderLen int = 9
FrameHeaderLen is the length of an HTTP/2 frame header, RFC 9113 §4.1.
Variables ¶
var ( // FrameMalformed refuses a frame that breaks its layout. FrameMalformed = errs.Static(CodeFrameMalformed, "FRAME_MALFORMED", "The HTTP/2 frame is malformed", "core/net/http2: a frame breaks the layout RFC 9113 gives it; the wire code says how", 0, 65) // HeadersTooLarge refuses a field block past the header list ceiling. HeadersTooLarge = errs.Static(CodeHeadersTooLarge, "HEADERS_TOO_LARGE", "The request header is too large", "core/net/http2: the field block passed the header list ceiling or the request value's field count", 431, 65) // CompressionFailed refuses a field block HPACK cannot decode. CompressionFailed = errs.Static(CodeCompressionFailed, "COMPRESSION_FAILED", "The HTTP/2 header block cannot be decoded", "core/net/http2: the field block holds a bad index, integer, string or size update (RFC 7541)", 0, 65) // FieldMalformed refuses a decoded field RFC 9113 §8.2.1 calls malformed. FieldMalformed = errs.Static(CodeFieldMalformed, "FIELD_MALFORMED", "The request header is malformed", "core/net/http2: a decoded field name or value is malformed (RFC 9113 §8.2.1); the block was decoded to its end", 0, 65) // LimitsRefused refuses a LimitsValue that cannot be honoured. LimitsRefused = errs.Static(CodeLimitsRefused, "LIMITS_REFUSED", "The HTTP/2 limits are not valid", "core/net/http2: a bound is out of its range; the reason field names it", 0, 78) )
Functions ¶
This section is empty.
Types ¶
type ErrCode ¶
type ErrCode uint32
ErrCode is an HTTP/2 error code, RFC 9113 §7: what RST_STREAM and GOAWAY carry. It is the wire's vocabulary, not an error of the SDK's: a refusal the codec answers with on the wire is an ErrCode, one it returns to a program is a sentinel of this package.
const ( // ErrCodeNoError is no error, a graceful shutdown or a discarded stream. ErrCodeNoError ErrCode = iota // ErrCodeProtocol is an unspecific protocol violation. ErrCodeProtocol // ErrCodeInternal is an unexpected internal failure of the endpoint. ErrCodeInternal // ErrCodeFlowControl is a flow-control violation. ErrCodeFlowControl // ErrCodeSettingsTimeout is a SETTINGS frame unanswered in time. ErrCodeSettingsTimeout // ErrCodeStreamClosed is a frame received on a closed stream. ErrCodeStreamClosed // ErrCodeFrameSize is a frame of the wrong size. ErrCodeFrameSize // ErrCodeRefusedStream is a stream refused before any processing. ErrCodeRefusedStream // ErrCodeCancel is a stream no longer wanted. ErrCodeCancel // ErrCodeCompression is a field block the connection's compression state // cannot survive. ErrCodeCompression // ErrCodeConnect is a CONNECT tunnel's failure. ErrCodeConnect // ErrCodeEnhanceYourCalm is a peer exhibiting excessive load. ErrCodeEnhanceYourCalm // ErrCodeInadequateSecurity is a transport below the minimum. ErrCodeInadequateSecurity // ErrCodeHTTP11Required asks the client to retry over HTTP/1.1. ErrCodeHTTP11Required )
type ErrorCountValue ¶
type ErrorCountValue struct {
// Type is the error counted.
Type ErrorType `json:"type"`
// Count is how many times it was.
Count uint64 `json:"count"`
}
ErrorCountValue is one row of a listener's HTTP/2 error table: an error type and how many times the group's engine counted it since Start.
type ErrorType ¶
type ErrorType uint8
ErrorType names an HTTP/2 error a group counts (#966): one per RFC 9113 code, numbered as the code is, and three the codes do not spell — a header list past its bound, a PING unanswered, and anything else. A fixed vocabulary, so a peer cannot grow the table.
const ( // ErrorTypeProtocol counts an error answered PROTOCOL_ERROR, an unspecific protocol violation. ErrorTypeProtocol ErrorType = iota + 1 // ErrorTypeInternal counts an error answered INTERNAL_ERROR, the endpoint's own failure. ErrorTypeInternal // ErrorTypeFlowControl counts an error answered FLOW_CONTROL_ERROR, a window overrun or overflowed. ErrorTypeFlowControl // ErrorTypeSettingsTimeout counts an error answered SETTINGS_TIMEOUT, a SETTINGS frame unanswered in time. ErrorTypeSettingsTimeout // ErrorTypeStreamClosed counts an error answered STREAM_CLOSED, a frame on a closed stream. ErrorTypeStreamClosed // ErrorTypeFrameSize counts an error answered FRAME_SIZE_ERROR, a frame of the wrong length. ErrorTypeFrameSize // ErrorTypeRefusedStream counts an error answered REFUSED_STREAM, a stream past the open-stream bound. ErrorTypeRefusedStream // ErrorTypeCancel counts an error answered CANCEL, a stream the endpoint no longer wanted. ErrorTypeCancel // ErrorTypeCompression counts an error answered COMPRESSION_ERROR, a field block HPACK refused. ErrorTypeCompression // ErrorTypeConnect counts an error answered CONNECT_ERROR, a CONNECT request's failure. ErrorTypeConnect // ErrorTypeEnhanceYourCalm counts an error answered ENHANCE_YOUR_CALM, a flood the codec cut short. ErrorTypeEnhanceYourCalm // ErrorTypeInadequateSecurity counts an error answered INADEQUATE_SECURITY, a transport below the minimum. ErrorTypeInadequateSecurity // ErrorTypeHTTP11Required counts an error answered HTTP_1_1_REQUIRED, a request HTTP/1.1 must carry. ErrorTypeHTTP11Required // ErrorTypeHeaderList counts a header list past the group's bound: answered 431 // or refused, it is no RFC 9113 error code. ErrorTypeHeaderList // ErrorTypePingTimeout counts a connection closed because a PING sent on its // silence went unanswered (ADR 0195 §D3). ErrorTypePingTimeout // ErrorTypeOther counts an error the engine named outside this vocabulary. ErrorTypeOther )
func ErrorTypeOf ¶
ErrorTypeOf is the ErrorType counting an error answered with code: the type of the same number for an RFC 9113 code, ErrorTypeOther for NO_ERROR and any code outside the RFC.
func (ErrorType) MarshalText ¶
MarshalText implements encoding.TextMarshaler: the name String gives.
type FrameFlags ¶
type FrameFlags uint8
FrameFlags is a frame header's flags byte, RFC 9113 §4.1.
const ( // FlagAck acknowledges a SETTINGS or a PING frame. FlagAck FrameFlags = 0x1 // FlagEndStream marks the last frame of a stream on DATA and HEADERS. FlagEndStream FrameFlags = 0x1 // FlagEndHeaders marks the last frame of a field block. FlagEndHeaders FrameFlags = 0x4 // FlagPadded marks a frame carrying a pad length and padding. FlagPadded FrameFlags = 0x8 // FlagPriority marks a HEADERS frame carrying a priority field. FlagPriority FrameFlags = 0x20 )
type FrameType ¶
type FrameType uint8
FrameType is an HTTP/2 frame's type, RFC 9113 §6. A type this package names no constant for is an extension frame, which an endpoint ignores (§4.1).
const ( // FrameData carries a stream's content, RFC 9113 §6.1. FrameData FrameType = iota // FrameHeaders opens a stream and carries its field block, §6.2. FrameHeaders // FramePriority is the deprecated priority signal, §6.3; ignored. FramePriority // FrameRSTStream ends a stream at once, §6.4. FrameRSTStream // FrameSettings carries or acknowledges a connection's settings, §6.5. FrameSettings // FramePushPromise reserves a server-initiated stream, §6.6. FramePushPromise // FramePing measures the round trip and checks liveness, §6.7. FramePing // FrameGoAway ends a connection gracefully or with an error, §6.8. FrameGoAway // FrameWindowUpdate grants flow-control credit, §6.9. FrameWindowUpdate // FrameContinuation extends a field block past one frame, §6.10. FrameContinuation )
type FrameValue ¶
type FrameValue struct {
// Type is the frame's type.
Type FrameType
// Flags is the frame's flags byte.
Flags FrameFlags
// StreamID is the stream the frame belongs to, the reserved top bit
// cleared; zero is the connection itself.
StreamID uint32
// Length is the frame's payload length, in bytes.
Length int
}
FrameValue is a frame's nine-byte header, read by the frame layer of internal/service/net/http2. The payload that follows is Length bytes.
type LimitsValue ¶
type LimitsValue struct {
// MaxStreams is how many streams a connection may hold open at once: the
// next one is refused with REFUSED_STREAM. Zero selects DefaultMaxStreams.
MaxStreams int `json:"max_streams"`
// ReceivePerStream is the window one stream's body may hold unread. Zero
// selects DefaultReceivePerStream.
ReceivePerStream int `json:"receive_per_stream"`
// ReceivePerConn is the window all of a connection's streams share. Zero
// selects four ReceivePerStream, so a handler that never reads its body
// does not stop the others.
ReceivePerConn int `json:"receive_per_conn"`
// MaxFrame is the largest frame the codec accepts, between
// DefaultMaxFrame and MaxFrameLimit. Zero selects DefaultMaxFrame.
MaxFrame int `json:"max_frame"`
// HeaderTable is the HPACK dynamic table the server advertises, at most
// MaxHeaderTable. Zero selects DefaultHeaderTable; NoDynamicTable
// advertises none.
HeaderTable int `json:"header_table"`
// MaxHeaderList bounds a request's header list as RFC 9113 §6.5.2 counts
// it, the name and value of each field plus 32. Zero selects
// DefaultMaxHeaderList.
MaxHeaderList int `json:"max_header_list"`
}
LimitsValue bounds what one HTTP/2 connection may do, the numbers ADR 0195 §D3 chose. A zero field selects its default, never unbounded (ADR 0031); a value it cannot honour is refused by Resolve, never narrowed in silence.
func (LimitsValue) Resolve ¶
func (v LimitsValue) Resolve() (LimitsValue, error)
Resolve returns v with each zero field replaced by its default. A negative field, a MaxFrame outside the protocol's range or a ReceivePerConn below ReceivePerStream is refused with LimitsRefused, naming the field in reason.
type SettingID ¶
type SettingID uint16
SettingID is a SETTINGS parameter's identifier, RFC 9113 §6.5.2.
const ( // SettingHeaderTableSize bounds the peer's HPACK dynamic table. SettingHeaderTableSize SettingID = 0x1 // SettingEnablePush says whether the peer may push. SettingEnablePush SettingID = 0x2 // SettingMaxConcurrentStreams bounds the peer's open streams. SettingMaxConcurrentStreams SettingID = 0x3 // SettingInitialWindowSize is the peer's initial stream window. SettingInitialWindowSize SettingID = 0x4 // SettingMaxFrameSize is the largest frame the peer accepts. SettingMaxFrameSize SettingID = 0x5 // SettingMaxHeaderListSize bounds the header list the peer accepts. SettingMaxHeaderListSize SettingID = 0x6 // SettingEnableConnectProtocol enables RFC 8441's extended CONNECT. SettingEnableConnectProtocol SettingID = 0x8 )
type SettingValue ¶
type SettingValue struct {
// ID identifies the parameter.
ID SettingID
// Val is the parameter's value.
Val uint32
}
SettingValue is one SETTINGS parameter as RFC 9113 §6.5.1 lays it out: a 16-bit identifier and a 32-bit value.