type DecodingError … func (de DecodingError) Error() string { … } type InvalidIndexError … func (e InvalidIndexError) Error() string { … } type HeaderField … // IsPseudo reports whether the header field is an http2 pseudo header. // That is, it reports whether it starts with a colon. // It is not otherwise guaranteed to be a valid pseudo header field, // though. func (hf HeaderField) IsPseudo() bool { … } func (hf HeaderField) String() string { … } // Size returns the size of an entry per RFC 7541 section 4.1. func (hf HeaderField) Size() uint32 { … } type Decoder … // NewDecoder returns a new decoder with the provided maximum dynamic // table size. The emitFunc will be called for each valid field // parsed, in the same goroutine as calls to Write, before Write returns. func NewDecoder(maxDynamicTableSize uint32, emitFunc func(f HeaderField)) *Decoder { … } var ErrStringLength … // SetMaxStringLength sets the maximum size of a HeaderField name or // value string. If a string exceeds this length (even after any // decompression), Write will return ErrStringLength. // A value of 0 means unlimited and is the default from NewDecoder. func (d *Decoder) SetMaxStringLength(n int) { … } // SetEmitFunc changes the callback used when new header fields // are decoded. // It must be non-nil. It does not affect EmitEnabled. func (d *Decoder) SetEmitFunc(emitFunc func(f HeaderField)) { … } // SetEmitEnabled controls whether the emitFunc provided to NewDecoder // should be called. The default is true. // // This facility exists to let servers enforce MAX_HEADER_LIST_SIZE // while still decoding and keeping in-sync with decoder state, but // without doing unnecessary decompression or generating unnecessary // garbage for header fields past the limit. func (d *Decoder) SetEmitEnabled(v bool) { … } // EmitEnabled reports whether calls to the emitFunc provided to NewDecoder // are currently enabled. The default is true. func (d *Decoder) EmitEnabled() bool { … } func (d *Decoder) SetMaxDynamicTableSize(v uint32) { … } // SetAllowedMaxDynamicTableSize sets the upper bound that the encoded // stream (via dynamic table size updates) may set the maximum size // to. func (d *Decoder) SetAllowedMaxDynamicTableSize(v uint32) { … } type dynamicTable … func (dt *dynamicTable) setMaxSize(v uint32) { … } func (dt *dynamicTable) add(f HeaderField) { … } // If we're too big, evict old stuff. func (dt *dynamicTable) evict() { … } func (d *Decoder) maxTableIndex() int { … } func (d *Decoder) at(i uint64) (hf HeaderField, ok bool) { … } // DecodeFull decodes an entire block. // // TODO: remove this method and make it incremental later? This is // easier for debugging now. func (d *Decoder) DecodeFull(p []byte) ([]HeaderField, error) { … } // Close declares that the decoding is complete and resets the Decoder // to be reused again for a new header block. If there is any remaining // data in the decoder's buffer, Close returns an error. func (d *Decoder) Close() error { … } func (d *Decoder) Write(p []byte) (n int, err error) { … } var errNeedMore … type indexType … const indexedTrue … const indexedFalse … const indexedNever … func (v indexType) indexed() bool { … } func (v indexType) sensitive() bool { … } // returns errNeedMore if there isn't enough data available. // any other error is fatal. // consumes d.buf iff it returns nil. // precondition: must be called with len(d.buf) > 0 func (d *Decoder) parseHeaderFieldRepr() error { … } // (same invariants and behavior as parseHeaderFieldRepr) func (d *Decoder) parseFieldIndexed() error { … } // (same invariants and behavior as parseHeaderFieldRepr) func (d *Decoder) parseFieldLiteral(n uint8, it indexType) error { … } func (d *Decoder) callEmit(hf HeaderField) error { … } // (same invariants and behavior as parseHeaderFieldRepr) func (d *Decoder) parseDynamicTableSizeUpdate() error { … } var errVarintOverflow … // readVarInt reads an unsigned variable length integer off the // beginning of p. n is the parameter as described in // https://httpwg.org/specs/rfc7541.html#rfc.section.5.1. // // n must always be between 1 and 8. // // The returned remain buffer is either a smaller suffix of p, or err != nil. // The error is errNeedMore if p doesn't contain a complete integer. func readVarInt(n byte, p []byte) (i uint64, remain []byte, err error) { … } // readString reads an hpack string from p. // // It returns a reference to the encoded string data to permit deferring decode costs // until after the caller verifies all data is present. func (d *Decoder) readString(p []byte) (u undecodedString, remain []byte, err error) { … } type undecodedString … func (d *Decoder) decodeString(u undecodedString) (string, error) { … }