hpack

Generated by tinox doc

tinox.core.hpack, split out of the bundled stdlib as a standalone tinox-central package.

Encode decode headers

import tinox.core.hpack

class Main
{
    fnc main() -> Int32
    {
        let encodeTable: HpackDynTable = HpackDynTable::new(4096)
        let headers: List<HpackHeader> = [
            HpackHeader::new(":method", "GET"),
            HpackHeader::new("x-request-id", "abc-123")
        ]
        let encoded: List<Int64> = Hpack::encode(headers, encodeTable)
        println("encoded " + encoded.len().toString() + " bytes")

        let decodeTable: HpackDynTable = HpackDynTable::new(4096)
        let decoded: List<HpackHeader> = Hpack::decode(encoded, decodeTable)
        println(decoded[0].name + ": " + decoded[0].value)
        println(decoded[1].name + ": " + decoded[1].value)
        return 0
    }
}

fn tinoxBytesToString(bytes: List<Int64>) → String

class Hpack

* HPACK encoder/decoder * * Decodes header blocks received from HTTP/2 clients and encodes * header lists into header blocks for HTTP/2 responses.

Methods

fn staticName(index: Int64) → String
* Returns the header name for a static table index (1-based, RFC 7541 Appendix A)
fn staticValue(index: Int64) → String
* Returns the header value for a static table index (only entries with non-empty values)
fn lookupHeader(dynTable: HpackDynTable, index: Int64) → HpackHeader
* Looks up a header from the combined static + dynamic index table (1-based)
fn decodeInt(data: List<Int64>, offset: Int64, prefixBits: Int64) → HpackIntResult
* Decodes an HPACK integer with the given prefix bit width (RFC 7541 §5.1) * * @param data the raw byte list * @param offset byte position of the first byte containing the prefix * @param prefixBits number of prefix bits (1–8) * @return HpackIntResult with decoded value and the offset of the next unconsumed byte
@Throwsfn decodeStr(data: List<Int64>, offset: Int64) → HpackStrResult
* Decodes an HPACK string literal (RFC 7541 §5.2) * Huffman-coded strings (flag bit 0x80) are decoded; see huffmanDecode. * * @param data the raw byte list * @param offset byte position of the string length/flag byte * @return HpackStrResult with the decoded string and next offset
@Throwsfn huffmanDecode(data: List<Int64>) → List<Int64>
@Throwsfn decode(data: List<Int64>, dynTable: HpackDynTable) → List<HpackHeader>
* Decodes a complete HPACK header block into a list of headers * * Handles all four representation types from RFC 7541 §6: * - Indexed header field (§6.1) * - Literal with incremental indexing (§6.2.1) * - Dynamic table size update (§6.3) * - Literal without/never indexed (§6.2.2, §6.2.3) * * @param data the raw HPACK-encoded header block bytes * @param dynTable the per-connection dynamic table (mutated by indexing) * @return list of decoded headers in field-section order
fn encodeInt(value: Int64, prefixBits: Int64, firstByteMask: Int64) → List<Int64>
* Encodes an integer with a given prefix bit width and high-byte mask (RFC 7541 §5.1)
fn encodeStr(s: String) → List<Int64>
* Encodes a string literal without Huffman coding (RFC 7541 §5.2)
fn findStatic(name: String, value: String) → Int64
* Searches the static table for a matching name+value pair. * Returns the index of a full match, or the index of the first name-only match, * or -1 if the name is not found at all.
fn encode(headers: List<HpackHeader>, dynTable: HpackDynTable) → List<Int64>
* Encodes a list of headers into an HPACK header block. * * Uses indexed representation for full static-table hits, * and literal with incremental indexing for everything else, * updating the dynamic table accordingly. * * @param headers list of headers to encode * @param dynTable the per-connection dynamic table (mutated) * @return raw HPACK-encoded bytes

class HpackDynTable

* HPACK dynamic table (RFC 7541 §2.3.2) * * New entries are prepended; eviction happens from the tail. * Each entry has an overhead of 32 octets per spec.

Fields

entriesList<HpackHeader>
maxSizeInt64
currentSizeInt64

Methods

fn new(maxSize: Int64) → HpackDynTable
fn add(header: HpackHeader) → Nothing
fn setMaxSize(newSize: Int64) → Nothing

@Errorclass HpackError

* Malformed HPACK data.

Fields

messageString

class HpackHeader

* A single decoded or to-be-encoded HTTP header name/value pair

Fields

nameString
valueString

Methods

fn new(name: String, value: String) → HpackHeader

class HpackIntResult

Fields

valueInt64
nextOffsetInt64

class HpackStrResult

Fields

valueString
nextOffsetInt64