[][src]Crate hpack_codec

Encoder and Decoder for HPACK (RFC 7541).

Examples

use hpack_codec::{Encoder, Decoder};
use hpack_codec::field::{HeaderField, LiteralHeaderField as Field};
use hpack_codec::table::{StaticEntry, Index};

// Encoding
let mut encoder = Encoder::new(4096);
let mut header = encoder.enter_header_block(Vec::new()).unwrap();
header.encode_field(StaticEntry::MethodGet).unwrap();
header.encode_field(Field::with_indexed_name(StaticEntry::Path, b"/hello")).unwrap();
header.encode_field(Field::new(b"foo", b"bar").with_indexing()).unwrap();
header.encode_field(Index::dynamic_table_offset() + 0).unwrap();
let encoded_data = header.finish();

// Decoding
let mut decoder = Decoder::new(4096);
let mut header = decoder.enter_header_block(&encoded_data[..]).unwrap();
assert_eq!(header.decode_field().unwrap(), HeaderField::new(b":method", b"GET").ok());
assert_eq!(header.decode_field().unwrap(), HeaderField::new(b":path", b"/hello").ok());
assert_eq!(header.decode_field().unwrap(), HeaderField::new(b"foo", b"bar").ok());
assert_eq!(header.decode_field().unwrap(), HeaderField::new(b"foo", b"bar").ok());

Modules

field

Header Field.

literal

Literal types.

table

Header Field Table.

Structs

Decoder

HPACK Decoder.

Encoder

HPACK Encoder.

HeaderBlockDecoder

Header Block Decoder.

HeaderBlockEncoder

Header Block Encoder.

Type Definitions

Error

This crate specific Error type.

Result

This crate specific Result type.