nahpack

Crates.ionahpack
lib.rsnahpack
version0.2.0
sourcesrc
created_at2015-08-28 00:30:04.334514
updated_at2015-12-11 23:54:29.779751
descriptionHPACK (RFC 7541) library
homepage
repositoryhttps://github.com/ijl/nahpack
max_upload_size
id2938
size200,470
(ijl)

documentation

README

nahpack

nahpack is an RFC 7541 HPACK encoder and decoder library.

It compresses, decompresses, and validates an HTTP/2 "header block" as contained in HEADERS, PUSH PROMISE, and CONTINUATION frames.

It is fully compatible with implementations submitted to the hpack-test-case repository.

Usage

This example decodes the C.3 case given in the HPACK RFC.

use nahpack::{decode_block, HpackContext, Headers};

let mut context = HpackContext::new();

{
    // first request
    let block = b"\x82\x86\x84A\x0fwww.example.com";
    let mut headers = Headers::new(block);
    match decode_block(&mut context, &mut headers) {
        Ok(_) => { },
        Err(_) => { }
    }
}
{
    // second request
    let block = b"\x82\x86\x84\xbe\x58\x08no-cache";
    let mut headers = Headers::new(block);
    match decode_block(&mut context, &mut headers) {
        Ok(_) => { },
        Err(_) => { }
    }
}
{
    // third request
    let block = b"\x82\x87\x85\xbf@\x88%\xa8I\xe9[\xa9}\x7f\x89%\xa8I\xe9[\xb8\xe8\xb4\xbf";
    let mut headers = Headers::new(block);
    match decode_block(&mut context, &mut headers) {
        Ok(_) => { },
        Err(_) => { }
    }
}

This example implements encoding of an HpackEncodable struct.

use nahpack::{encode_block, HpackEncodable, HpackContext};

struct Header {
    name: &'static [u8],
    value: &'static [u8],
    is_compressable: bool,
}

impl HpackEncodable for Header {

    fn name(&self) -> &'static [u8] { self.name }
    fn value(&self) -> &'static [u8] { self.value }
    fn is_compressable(&self) -> bool { self.is_compressable.clone() }

}

let headers = vec![
    Header { name: b":method", value: b"GET", is_compressable: true },
    Header { name: b":scheme", value: b"http", is_compressable: true },
    Header { name: b":path", value: b"/", is_compressable: true },
    Header { name: b":authority", value: b"www.example.com", is_compressable: true },
];

let mut context = HpackContext::new();
let mut writer: Vec<u8> = Vec::new();

let num_bytes = encode_block(&mut writer, &headers, &mut context, 0);

Misc

nahpack is licensed under the Mozilla Public License, Version 2.0.

The author's repository is https://github.com/ijl/nahpack, and the repository's commmits are signed with the below key of ijl@mailbox.org:

-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBFW9gpwBEACthh7QdDj0lnid+N/6sT8piGcvCK6REG35ffZ2Rt4dV7aqJcx9
UvdOqAE8XMLR3sw3MyQHBa9L3ugGzPfFNhSFlrQYFIibM8iCVAMFK551K35xKjjF
hETJGl/eqtzzwJgeH2V53+z8epzeGOnm6fxIt+bBbAVRbg4nqtlw3fu5eKQ1WXeM
jrOEsU9vxlxd2DlEw/oPr9aN4p2YtGfKf/XCIipyh1fvf9Iyhz1a0rAziHdPyg0B
TIlVKPWHkKl0x+TfWyg4AEqFp38xEETaJLbwByKLmprbF5rU3RgWXpt0ZtZpu2dx
W1tBnMe5EMrBuzI28NUMdi3SO06pQ6j11veHmx8rJhwdbqQgnWiaTEynsbhFRSDQ
BH6Vyv2XyObdge5+42g781E20XQwKkPv0YFeEOuZjfdeAgiLo0vmrAHzG5negceu
52106aE2CMMax6iUZDm2cLNQLmrVqx645Ep6sRL6UbyRWL0MNxp2xi05/Tu9YhrW
cQsyMV1IPIg6txMqi//aaEcAM4DRbqMOrPygIha67qpX4BN2EWUZu/t8/VHWVEEA
1C6rnwxmPzeBZKsSBJb2D6JE1MWUvDS7fm8+kr4wRKhMJRpIf8RGAG4RZazKOp40
vg9bFdSLSHBWqsA9YagH8BFOLHUY93QTIxhtd7NZmX2FIzSck7HJYPkwPQARAQAB
tBVpamwgPGlqbEBtYWlsYm94Lm9yZz6JAj0EEwEKACcFAlW9gpwCGwMFCQWjmoAF
CwkIBwMFFQoJCAsFFgIDAQACHgECF4AACgkQKU/QGeIVQIKc5A//WdeSnOpDAyFW
ojzV0JUquDD2zBq6fffBtbpHITRCStd1DRESVtkL1hj7h3l+JeNEkvxMqwnHmjhX
ShwMjnYmNL1QWweLAZ1YQFXShhlxgbyZlXJ0Lria6vGSwdNxg4y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