[][src]Crate httlib_hpack

This crate implements HPACK, a compression format for efficiently representing HTTP header fields in HTTP/2. It exposes a simple API for performing the encoding and decoding of HTTP headers.

Documentation Source

About

HPACK is a compression format that eliminates redundant header fields in requests and responses. This is one of the features based on which the HTTP/2 protocol significantly reduces the amount of transferred data from one entity to another.

A significant shift in thinking is required from the implementer of the HTTP/2 protocol. A connection in HTTP/2 does not represent a single request/response session. We can start multiple simultaneous streams in one connection, representing multiple request/response sessions, which was not possible in the previous versions of the HTTP protocol. The HPACK compressor uses this characteristic of HTTP/2 by indexing headers considering the whole connection and not per stream.

The implementation of HPACK contains three main parts of the process:

  • Indexing table is a list, to which the HPACK saves the commonly used headers. Each entity indexes headers per connection, separately for incoming (decoding) and for outgoing (encoding) data (2.3.).

  • Encoder TODO!!!!!

  • Decoder TODO!!!!!

Usage

Encoding example:

use httlib_hpack::Encoder;
 
let mut encoder = Encoder::default();
let mut dst = Vec::new();
let name = b":method".to_vec();
let value = b"PATCH".to_vec();
let flags = Encoder::HUFFMAN_VALUE | Encoder::WITH_INDEXING | Encoder::BEST_FORMAT;
encoder.encode((name, value, flags), &mut dst).unwrap();

Decoding example:

use httlib_hpack::Decoder;

let mut decoder = Decoder::default();
let mut buf = vec![0x80 | 2];
let mut dst = Vec::new();
decoder.decode(&mut buf, &mut dst).unwrap();
 
for (name, value, flags) in dst {
    if flags & Decoder::NEVER_INDEXED == Decoder::NEVER_INDEXED {
        // sensitive header
    } else {
        // common header
    }
}

Articles

Structs

Decoder

An object for decoding HTTP/2 headers.

Encoder

An object for encoding HTTP/2 headers.

Table

This table represents a single index address space for headers where the static and the dynamic table are combined.

TableIter

An iterator through all the entries in the table. This iterator will first walk through entries of the static table and then through entries of the dynamic table.

Enums

DecoderError

Represents all errors that can be encountered while performing the decoding of an HPACK header set.

DecoderSpeed

All the decoding speed options which represent the number of bits that the decoder can read at a time.

EncoderError

Represents all errors that can be encountered while performing the encoding of an HPACK header set.

EncoderInput

An enum representing encoder input formats.

Functions

decode_integer

Decodes an integer number encoded with a given prefix size (in bits) based on the pseudocode provided by the HPACK specification ([5.1]).

decode_string

Decodes HPACK encoded string to plain test ([5.2]).