GithubHelp home page GithubHelp logo

hpack-rs's Introduction

hpack-rs

Build Status

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.

hpack-rs's People

Contributors

mlalic avatar waieez avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.