Module hpack::decoder [] [src]

Exposes the struct Decoder that allows for HPACK-encoded header blocks to be decoded into a header list.

The decoder only follows HPACK rules, without performing any additional (semantic) checks on the header name/value pairs, i.e. it considers the headers as opaque octets.

Example

A simple example of using the decoder that demonstrates its API:

use hpack::Decoder;
let mut decoder = Decoder::new();

let header_list = decoder.decode(&[0x82, 0x84]).unwrap();

assert_eq!(header_list, [
    (b":method".to_vec(), b"GET".to_vec()),
    (b":path".to_vec(), b"/".to_vec()),
]);

A more complex example where the callback API is used, providing the client a borrowed representation of each header, rather than an owned representation.

use hpack::Decoder;
let mut decoder = Decoder::new();

let mut count = 0;
let header_list = decoder.decode_with_cb(&[0x82, 0x84], |name, value| {
    count += 1;
    match count {
        1 => {
            assert_eq!(&name[..], &b":method"[..]);
            assert_eq!(&value[..], &b"GET"[..]);
        },
        2 => {
            assert_eq!(&name[..], &b":path"[..]);
            assert_eq!(&value[..], &b"/"[..]);
        },
        _ => panic!("Did not expect more than two headers!"),
    };
});

Structs

Decoder

Decodes headers encoded using HPACK.

Enums

DecoderError

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

IntegerDecodingError

Represents all errors that can be encountered while decoding an integer.

StringDecodingError

Represents all errors that can be encountered while decoding an octet string.

Type Definitions

DecoderResult

The result returned by the decode method of the Decoder.