Documentation
¶
Overview ¶
Package frame provides HTTP/2 frame type definitions, parsing, writing, and HPACK integration.
Index ¶
- Constants
- func ValidateClientPreface(buf []byte) bool
- type Flags
- type Frame
- type HeaderDecoder
- type HeaderEncoder
- type Parser
- type RawFrame
- type Type
- type Writer
- func (w *Writer) Close() error
- func (w *Writer) CloseImmediate() error
- func (w *Writer) Flush() error
- func (w *Writer) WriteData(streamID uint32, endStream bool, data []byte) error
- func (w *Writer) WriteFrame(f *Frame) error
- func (w *Writer) WriteGoAway(lastStreamID uint32, code http2.ErrCode, debugData []byte) error
- func (w *Writer) WriteHeaders(streamID uint32, endStream bool, headerBlock []byte, maxFrameSize uint32) error
- func (w *Writer) WritePing(ack bool, data [8]byte) error
- func (w *Writer) WritePushPromise(streamID uint32, promiseID uint32, endHeaders bool, headerBlock []byte) error
- func (w *Writer) WriteRSTStream(streamID uint32, code http2.ErrCode) error
- func (w *Writer) WriteSettings(settings ...http2.Setting) error
- func (w *Writer) WriteSettingsAck() error
- func (w *Writer) WriteWindowUpdate(streamID uint32, increment uint32) error
Constants ¶
const ClientPreface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
ClientPreface is the HTTP/2 client connection preface string.
Variables ¶
This section is empty.
Functions ¶
func ValidateClientPreface ¶
ValidateClientPreface checks whether buf begins with a valid HTTP/2 client preface.
Types ¶
type HeaderDecoder ¶
type HeaderDecoder struct {
// contains filtered or unexported fields
}
HeaderDecoder decodes HTTP headers using HPACK.
func NewHeaderDecoder ¶
func NewHeaderDecoder(maxSize uint32) *HeaderDecoder
NewHeaderDecoder creates a new header decoder.
type HeaderEncoder ¶
type HeaderEncoder struct {
// contains filtered or unexported fields
}
HeaderEncoder encodes HTTP headers using HPACK.
func NewHeaderEncoder ¶
func NewHeaderEncoder() *HeaderEncoder
NewHeaderEncoder creates a new header encoder.
func (*HeaderEncoder) Close ¶
func (e *HeaderEncoder) Close()
Close releases internal resources back to the pool.
func (*HeaderEncoder) Encode ¶
func (e *HeaderEncoder) Encode(headers [][2]string) ([]byte, error)
Encode encodes headers to HPACK format. Returns a copy safe for concurrent use.
func (*HeaderEncoder) EncodeBorrow ¶
func (e *HeaderEncoder) EncodeBorrow(headers [][2]string) ([]byte, error)
EncodeBorrow encodes headers and returns a byte slice backed by the encoder's internal buffer. The returned slice is only valid until the next call to Encode/EncodeBorrow or Close.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles HTTP/2 frame parsing.
func (*Parser) InitReader ¶
InitReader binds the parser to a persistent reader. This allows the framer to preserve CONTINUATION expectations across frames and read progressively as more data arrives.
type RawFrame ¶ added in v1.1.0
RawFrame is a zero-copy frame representation. Payload is a slice into the caller's buffer and is only valid until the next buffer modification.
func ReadRawFrame ¶ added in v1.1.0
ReadRawFrame parses a raw frame from buf without allocating. Returns the frame and the total number of bytes consumed (9 + payload length). Returns io.ErrUnexpectedEOF if buf doesn't contain a complete frame.
func (RawFrame) HasEndHeaders ¶ added in v1.1.0
HasEndHeaders reports whether the END_HEADERS flag (0x04) is set.
func (RawFrame) HasEndStream ¶ added in v1.1.0
HasEndStream reports whether the END_STREAM flag (0x01) is set.
func (RawFrame) HasPadded ¶ added in v1.1.0
HasPadded reports whether the PADDED flag (0x08) is set.
func (RawFrame) HasPriority ¶ added in v1.1.0
HasPriority reports whether the PRIORITY flag (0x20) is set (HEADERS frames).
type Type ¶
type Type uint8
Type represents HTTP/2 frame types.
const ( FrameData Type = 0x0 FrameHeaders Type = 0x1 FramePriority Type = 0x2 FrameRSTStream Type = 0x3 FrameSettings Type = 0x4 FramePushPromise Type = 0x5 FramePing Type = 0x6 FrameGoAway Type = 0x7 FrameWindowUpdate Type = 0x8 FrameContinuation Type = 0x9 )
HTTP/2 frame type constants as defined in RFC 7540 Section 6.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer handles HTTP/2 frame writing with mutex protection.
func (*Writer) CloseImmediate ¶
CloseImmediate immediately closes the underlying writer.
func (*Writer) WriteFrame ¶
WriteFrame writes a generic frame.
func (*Writer) WriteGoAway ¶
WriteGoAway writes a GOAWAY frame.
func (*Writer) WriteHeaders ¶
func (w *Writer) WriteHeaders(streamID uint32, endStream bool, headerBlock []byte, maxFrameSize uint32) error
WriteHeaders writes HEADERS (and CONTINUATION) frames, fragmenting by maxFrameSize.
func (*Writer) WritePushPromise ¶
func (w *Writer) WritePushPromise(streamID uint32, promiseID uint32, endHeaders bool, headerBlock []byte) error
WritePushPromise writes a PUSH_PROMISE frame.
func (*Writer) WriteRSTStream ¶
WriteRSTStream writes a RST_STREAM frame.
func (*Writer) WriteSettings ¶
WriteSettings writes a SETTINGS frame.
func (*Writer) WriteSettingsAck ¶
WriteSettingsAck writes a SETTINGS acknowledgment frame.