Crates.io | hpack_codec |
lib.rs | hpack_codec |
version | 0.1.1 |
source | src |
created_at | 2017-09-18 06:03:22.605067 |
updated_at | 2019-11-12 14:11:08.751508 |
description | Encoder and Decoder for HPACK (RFC 7541) |
homepage | https://github.com/sile/hpack_codec |
repository | https://github.com/sile/hpack_codec |
max_upload_size | |
id | 32109 |
size | 107,621 |
Encoder and Decoder for HPACK (RFC 7541).
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());