velt/net/http/h2
API referenceHTTP/2's wire format (RFC 9113) and HPACK (RFC 7541), written in Velt: what the fetch client and HTTP/2 servers (the HTTP server package is one) share. It works on bytes (u8[] buffers and offsets) and leaves connections, streams and flow control to its users. For a walkthrough, read the guide.
Exports
code, for messages.frameLengthThe 24-bit payload length of the frame header at b[at..].isPrefaceWhether b[at..at + 24) is the client preface.mayBePrefaceWhether the bytes b[at..end) (fewer than 24) may still turn out to be the preface.readStreamIdThe 31-bit stream id at b[at..at + 4) (the reserved bit ignored).readU32The 32-bit number at b[at..at + 4).huffmanDecodeDecodes the Huffman-coded bytes src[start..end) into out from at: the end of what was written, or -1 for input that is not a valid code (EOS, or padding that is not up to 7 one bits).huffmanEncodeWrites the Huffman code of src[start..end) into out from at (room for huffmanLength bytes), padded with one bits: the end of what was written.huffmanLengthThe number of bytes the Huffman code of src[start..end) takes.FieldListDecoded header fields: bytes and ranges.FrameWriterAn output buffer of frames.HpackDecoderA header block's decoder for one connection.HpackEncoderA connection's response header encoder.ACKFlag: an acknowledgement (SETTINGS, PING).CANCELError code: the stream is no longer needed.COMPRESSION_ERRORError code: the HPACK state could not be kept.CONNECT_ERRORError code: a CONNECT tunnel failed.CONTINUATIONA CONTINUATION frame: the rest of a header block (§6.10).DATAA DATA frame: part of a stream's body (§6.1).DEFAULT_WINDOWThe default initial flow-control window (RFC 9113 §6.9.1).END_HEADERSFlag: the header block's last frame (HEADERS, CONTINUATION).END_STREAMFlag: the stream's last frame from this side (DATA, HEADERS).ENHANCE_YOUR_CALMError code: the peer generates too much load.FLOW_CONTROL_ERRORError code: the peer broke flow control.FRAME_SIZE_ERRORError code: a frame had the wrong size.GOAWAYA GOAWAY frame: the connection ends after the streams up to its last one (§6.8).HEADER_LENGTHThe frame header's length: 24-bit length, type, flags, 31-bit stream id.HEADERSA HEADERS frame: a header block, or its first part (§6.2).HTTP_1_1_REQUIREDError code: use HTTP/1.1 for this request.INADEQUATE_SECURITYError code: the TLS parameters are not good enough.INTERNAL_ERRORError code: the endpoint failed.MAX_MAX_FRAME_SIZEThe largest SETTINGS_MAX_FRAME_SIZE allowed.MAX_WINDOWThe largest a flow-control window may be.MIN_MAX_FRAME_SIZEThe default and smallest SETTINGS_MAX_FRAME_SIZE.NO_ERRORError code: none (a graceful end).PADDEDFlag: the payload is padded (DATA, HEADERS).PINGA PING frame, answered with its ACK (§6.7).PREFACE_LENGTHThe client connection preface (RFC 9113 §3.4): "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".PRIORITYA PRIORITY frame, deprecated and ignored (§6.3).PRIORITY_FLAGFlag: HEADERS carries priority fields (deprecated, skipped).PROTOCOL_ERRORError code: the peer broke the protocol.PUSH_PROMISEA PUSH_PROMISE frame (server push, which this implementation turns off) (§6.6).REFUSED_STREAMError code: the stream was refused before any processing (safe to retry).RST_STREAMAn RST_STREAM frame: ends one stream at once (§6.4).SETTINGSA SETTINGS frame: the sender's settings, or the acknowledgement of the peer's (§6.5).SETTINGS_ENABLE_CONNECT_PROTOCOLRFC 8441: extended CONNECT (WebSockets over HTTP/2).SETTINGS_ENABLE_PUSHSetting: whether server push is allowed (0 or 1).SETTINGS_HEADER_TABLE_SIZESetting: the largest HPACK dynamic table the sender's decoder allows.SETTINGS_INITIAL_WINDOW_SIZESetting: a new stream's flow-control window.SETTINGS_MAX_CONCURRENT_STREAMSSetting: the most streams the peer may have open at once.SETTINGS_MAX_FRAME_SIZESetting: the largest frame payload the sender accepts.SETTINGS_MAX_HEADER_LIST_SIZESetting: the largest header list the sender accepts (advisory).SETTINGS_TIMEOUTError code: SETTINGS were not acknowledged in time.STREAM_CLOSEDError code: a frame came for a half-closed stream.WINDOW_UPDATEA WINDOW_UPDATE frame: more of a flow-control window (§6.9).Re-exported from velt/net/http/h2/frame
function errorName(code: i64): stringThe name of error code code, for messages.
Re-exported from velt/net/http/h2/frame
function frameLength(b: u8[], at: i64): i64The 24-bit payload length of the frame header at b[at..].
Re-exported from velt/net/http/h2/frame
function isPreface(b: u8[], at: i64): boolWhether b[at..at + 24) is the client preface.
Re-exported from velt/net/http/h2/frame
function mayBePreface(b: u8[], at: i64, end: i64): boolWhether the bytes b[at..end) (fewer than 24) may still turn out to be the preface.
Re-exported from velt/net/http/h2/frame
function readStreamId(b: u8[], at: i64): i64The 31-bit stream id at b[at..at + 4) (the reserved bit ignored).
Re-exported from velt/net/http/h2/frame
function readU32(b: u8[], at: i64): i64The 32-bit number at b[at..at + 4).
Re-exported from velt/net/http/h2/huffman
function huffmanDecode(
src: u8[],
start: i64,
end: i64,
out: u8[],
at: i64,
): i64Decodes the Huffman-coded bytes src[start..end) into out from at: the end of what was
written, or -1 for input that is not a valid code (EOS, or padding that is not up to 7 one
bits). out must have room for (end - start) * 8 / 5 bytes (the shortest code is 5 bits).
Re-exported from velt/net/http/h2/huffman
function huffmanEncode(
src: u8[],
start: i64,
end: i64,
out: u8[],
at: i64,
): i64Writes the Huffman code of src[start..end) into out from at (room for huffmanLength
bytes), padded with one bits: the end of what was written.
Re-exported from velt/net/http/h2/huffman
function huffmanLength(src: u8[], start: i64, end: i64): i64The number of bytes the Huffman code of src[start..end) takes.
Re-exported from velt/net/http/h2/field_list
Decoded header fields: bytes and ranges.
Parameter ofHpackDecoder.decode
buf: u8[] = Buffer.alloc(512)No doc comment yetlength: i64 = 0The bytes of buf in use.
heads: i64[] = []Four offsets per field.
size: i64 = 0The list's size as SETTINGS_MAX_HEADER_LIST_SIZE counts it (each field + 32).
overflow: bool = falseA field did not fit within the limit: the later ones were decoded but not kept.
clear()Empties the list for the next block.
get count(): i64The number of fields.
reserve(n: i64)Room for n more bytes.
text(s: string)Appends the bytes of s.
bytes(b: u8[])Appends b.
name(i: i64): stringField i's name as text.
value(i: i64): stringField i's value as text.
nameIs(i: i64, s: string): boolWhether field i's name is s (lowercase, as HTTP/2 sends names).
nameLength(i: i64): i64The length of field i's name.
nameByte(i: i64): u8The first byte of field i's name.
pairs(): [string, string][]Field i as name: value pairs, for tests and errors.
Re-exported from velt/net/http/h2/frame_writer
An output buffer of frames.
Parameter ofHpackEncoder.begin
buf: u8[] = Buffer.alloc(16384)No doc comment yetlength: i64 = 0No doc comment yetreserve(n: i64)Room for n more bytes.
header(length: i64, type: i64, flags: i64, stream: i64)A frame header (room for it is the caller's: reserve).
u32(v: i64)A 32-bit number (room for it is the caller's).
byte(v: i64)One byte (room for it is the caller's).
settings(pairs: i64[])A SETTINGS frame with pairs (identifier, value, ...).
settingsAck()A SETTINGS acknowledgement.
pingAck(src: u8[], at: i64)A PING acknowledgement echoing src[at..at + 8).
goaway(lastStream: i64, code: i64, debug: string)A GOAWAY frame: the last stream processed, the error code and a debug text.
rstStream(stream: i64, code: i64)RST_STREAM for stream with error code.
windowUpdate(stream: i64, increment: i64)WINDOW_UPDATE of stream (0: the connection) by increment.
data(stream: i64, flags: i64, src: u8[], start: i64, end: i64)A DATA frame of stream carrying src[start..end).
beginHeaders(): i64Starts a HEADERS frame of stream: its header is filled in by endHeaders, once the block
(written after it) is known. Returns where the frame starts.
endHeaders(at: i64, stream: i64, flags: i64, maxFrame: i64)Ends the HEADERS frame begun at at (flags besides END_HEADERS: END_STREAM or none):
a block larger than maxFrame is split into HEADERS and CONTINUATION frames, which leave
together (RFC 9113 §4.3).
Re-exported from velt/net/http/h2/hpack_decoder
A header block's decoder for one connection.
table: DynamicTableThe dynamic table (public for tests).
maxListSize: i64The most a block's fields may add up to (SETTINGS_MAX_HEADER_LIST_SIZE).
constructor(tableSize: i64 = 4096, maxListSize: i64 = 16384)No doc comment yetdecode(src: u8[], start: i64, end: i64, out: FieldList): boolDecodes the block src[start..end) into out (appended): false when it is not valid HPACK
(a COMPRESSION_ERROR, which ends the connection). Fields beyond maxListSize set
out.overflow and are not kept.
Re-exported from velt/net/http/h2/hpack_encoder
A connection's response header encoder.
setMaxSize(size: i64)The peer's decoder allows size bytes of table (SETTINGS_HEADER_TABLE_SIZE): the encoder
uses at most 4096 of them, and announces a reduction with its next block.
begin(out: FrameWriter)Starts a block: a pending table size update goes first (RFC 7541 §4.2).
status(out: FrameWriter, code: i64):status code.
request(out: FrameWriter, method: string, scheme: string, authority: string, path: string)A request's pseudo-headers (the client side): the static table's entries where they match
(GET, POST, /, http, https), else literals by static name.
contentLength(out: FrameWriter, n: i64)content-length: n, without indexing (static name 28).
field(out: FrameWriter, name: string, value: string)Field name: value (name in lowercase).
Re-exported from velt/net/http/h2/frame
const ACK: i64 = 0x1Flag: an acknowledgement (SETTINGS, PING).
Re-exported from velt/net/http/h2/frame
const CANCEL: i64 = 8Error code: the stream is no longer needed.
Re-exported from velt/net/http/h2/frame
const COMPRESSION_ERROR: i64 = 9Error code: the HPACK state could not be kept.
Re-exported from velt/net/http/h2/frame
const CONNECT_ERROR: i64 = 10Error code: a CONNECT tunnel failed.
Re-exported from velt/net/http/h2/frame
const CONTINUATION: i64 = 9A CONTINUATION frame: the rest of a header block (§6.10).
Re-exported from velt/net/http/h2/frame
const DATA: i64 = 0A DATA frame: part of a stream's body (§6.1).
Re-exported from velt/net/http/h2/frame
const DEFAULT_WINDOW: i64 = 65535The default initial flow-control window (RFC 9113 §6.9.1).
Re-exported from velt/net/http/h2/frame
const END_HEADERS: i64 = 0x4Flag: the header block's last frame (HEADERS, CONTINUATION).
Re-exported from velt/net/http/h2/frame
const END_STREAM: i64 = 0x1Flag: the stream's last frame from this side (DATA, HEADERS).
Re-exported from velt/net/http/h2/frame
const ENHANCE_YOUR_CALM: i64 = 11Error code: the peer generates too much load.
Re-exported from velt/net/http/h2/frame
const FLOW_CONTROL_ERROR: i64 = 3Error code: the peer broke flow control.
Re-exported from velt/net/http/h2/frame
const FRAME_SIZE_ERROR: i64 = 6Error code: a frame had the wrong size.
Re-exported from velt/net/http/h2/frame
const GOAWAY: i64 = 7A GOAWAY frame: the connection ends after the streams up to its last one (§6.8).
Re-exported from velt/net/http/h2/frame
const HEADER_LENGTH: i64 = 9The frame header's length: 24-bit length, type, flags, 31-bit stream id.
Re-exported from velt/net/http/h2/frame
const HEADERS: i64 = 1A HEADERS frame: a header block, or its first part (§6.2).
Re-exported from velt/net/http/h2/frame
const HTTP_1_1_REQUIRED: i64 = 13Error code: use HTTP/1.1 for this request.
Re-exported from velt/net/http/h2/frame
const INADEQUATE_SECURITY: i64 = 12Error code: the TLS parameters are not good enough.
Re-exported from velt/net/http/h2/frame
const INTERNAL_ERROR: i64 = 2Error code: the endpoint failed.
Re-exported from velt/net/http/h2/frame
const MAX_MAX_FRAME_SIZE: i64 = 16777215The largest SETTINGS_MAX_FRAME_SIZE allowed.
Re-exported from velt/net/http/h2/frame
const MAX_WINDOW: i64 = 0x7fffffffThe largest a flow-control window may be.
Re-exported from velt/net/http/h2/frame
const MIN_MAX_FRAME_SIZE: i64 = 16384The default and smallest SETTINGS_MAX_FRAME_SIZE.
Re-exported from velt/net/http/h2/frame
const NO_ERROR: i64 = 0Error code: none (a graceful end).
Re-exported from velt/net/http/h2/frame
const PADDED: i64 = 0x8Flag: the payload is padded (DATA, HEADERS).
Re-exported from velt/net/http/h2/frame
const PING: i64 = 6A PING frame, answered with its ACK (§6.7).
Re-exported from velt/net/http/h2/frame
const PREFACE_LENGTH: i64 = 24The client connection preface (RFC 9113 §3.4): "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".
Re-exported from velt/net/http/h2/frame
const PRIORITY: i64 = 2A PRIORITY frame, deprecated and ignored (§6.3).
Re-exported from velt/net/http/h2/frame
const PRIORITY_FLAG: i64 = 0x20Flag: HEADERS carries priority fields (deprecated, skipped).
Re-exported from velt/net/http/h2/frame
const PROTOCOL_ERROR: i64 = 1Error code: the peer broke the protocol.
Re-exported from velt/net/http/h2/frame
const PUSH_PROMISE: i64 = 5A PUSH_PROMISE frame (server push, which this implementation turns off) (§6.6).
Re-exported from velt/net/http/h2/frame
const REFUSED_STREAM: i64 = 7Error code: the stream was refused before any processing (safe to retry).
Re-exported from velt/net/http/h2/frame
const RST_STREAM: i64 = 3An RST_STREAM frame: ends one stream at once (§6.4).
Re-exported from velt/net/http/h2/frame
const SETTINGS: i64 = 4A SETTINGS frame: the sender's settings, or the acknowledgement of the peer's (§6.5).
Re-exported from velt/net/http/h2/frame
const SETTINGS_ENABLE_CONNECT_PROTOCOL: i64 = 8RFC 8441: extended CONNECT (WebSockets over HTTP/2).
Re-exported from velt/net/http/h2/frame
const SETTINGS_ENABLE_PUSH: i64 = 2Setting: whether server push is allowed (0 or 1).
Re-exported from velt/net/http/h2/frame
const SETTINGS_HEADER_TABLE_SIZE: i64 = 1Setting: the largest HPACK dynamic table the sender's decoder allows.
Re-exported from velt/net/http/h2/frame
const SETTINGS_INITIAL_WINDOW_SIZE: i64 = 4Setting: a new stream's flow-control window.
Re-exported from velt/net/http/h2/frame
const SETTINGS_MAX_CONCURRENT_STREAMS: i64 = 3Setting: the most streams the peer may have open at once.
Re-exported from velt/net/http/h2/frame
const SETTINGS_MAX_FRAME_SIZE: i64 = 5Setting: the largest frame payload the sender accepts.
Re-exported from velt/net/http/h2/frame
const SETTINGS_MAX_HEADER_LIST_SIZE: i64 = 6Setting: the largest header list the sender accepts (advisory).
Re-exported from velt/net/http/h2/frame
const SETTINGS_TIMEOUT: i64 = 4Error code: SETTINGS were not acknowledged in time.
Re-exported from velt/net/http/h2/frame
const STREAM_CLOSED: i64 = 5Error code: a frame came for a half-closed stream.
Re-exported from velt/net/http/h2/frame
const WINDOW_UPDATE: i64 = 8A WINDOW_UPDATE frame: more of a flow-control window (§6.9).