6 releases (3 breaking)

Uses old Rust 2015

0.3.0 Oct 22, 2015
0.2.0 Apr 11, 2015
0.1.0 Apr 4, 2015
0.0.3 Apr 2, 2015
0.0.2 Mar 28, 2015

⚠️ Issues reported

#736 in Compression

Download history 1077/week @ 2024-07-21 1028/week @ 2024-07-28 1126/week @ 2024-08-04 2058/week @ 2024-08-11 1192/week @ 2024-08-18 1208/week @ 2024-08-25 1141/week @ 2024-09-01 891/week @ 2024-09-08 810/week @ 2024-09-15 1153/week @ 2024-09-22 877/week @ 2024-09-29 425/week @ 2024-10-06 880/week @ 2024-10-13 728/week @ 2024-10-20 853/week @ 2024-10-27 891/week @ 2024-11-03

3,374 downloads per month
Used in 260 crates (3 directly)

MIT license

135KB
2.5K SLoC

hpack-rs

Travis Build Status AppVeyor Build Status Coveralls master Crates.io

An HPACK coder implementation in Rust.

API Documentation

Overview

The library lets you perform header compression and decompression according to the HPACK spec.

The decoder module implements the API for performing HPACK decoding. The Decoder struct will track the decoding context during its lifetime (i.e. subsequent headers on the same connection should be decoded using the same instance).

The decoder implements the full spec and allows for decoding any valid sequence of bytes representing a compressed header list.

The encoder module implements the API for performing HPACK encoding. The Encoder struct will track the encoding context during its lifetime (i.e. the same instance should be used to encode all headers on the same connection).

The encoder so far does not implement Huffman string literal encoding; this, however, is enough to be able to send requests to any HPACK-compliant server, as Huffman encoding is completely optional.

Examples

Encoding

Encode some pseudo-headers that are fully indexed by the static header table.

use hpack::Encoder;

let mut encoder = Encoder::new();
let headers = vec![
    (b":method".to_vec(), b"GET".to_vec()),
    (b":path".to_vec(), b"/".to_vec()),
];
// The headers are encoded by providing their index (with a bit flag
// indicating that the indexed representation is used).
assert_eq!(encoder.encode(&headers), vec![2 | 0x80, 4 | 0x80]);

Decoding

Decode the headers from a raw byte sequence. In this case both of them are indexed by the static table.

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()),
]);

Interoperability

The decoder is tested for interoperability with HPACK encoders that have published their results to the http2jp/hpack-test-case repo.

License

The project is published under the terms of the MIT License.

Dependencies

~220KB