Function nahpack::decode_block [] [src]

pub fn decode_block<'h>(
    context: &mut HpackContext,
    headers: &mut Headers<'h>
) -> Result<(), HpackDecodeError>

Decode an HTTP/2 header block transmitted in one or more HEADERS, PUSH_PROMISE, or CONTINUATION frames. If the header block was split across multiple frames, they must first be merged.

If the header block is invalid, an HpackDecodeError is returned. These are all fatal, and in the HTTP/2 spec require that an error be returned to the sender.

Examples

This implements the C.3 example from the HPACK RFC's.

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(_) => { }
    }
}