#http #web

http-muncher

Rust Streaming HTTP parser based on nodejs/http-parser

10 releases

Uses old Rust 2015

0.3.2 May 24, 2018
0.3.1 Dec 23, 2016
0.3.0 Oct 10, 2016
0.2.4 Jun 13, 2016
0.2.0 Jul 10, 2015

#148 in #http

Download history 166/week @ 2021-06-25 195/week @ 2021-07-02 196/week @ 2021-07-09 126/week @ 2021-07-16 153/week @ 2021-07-23 192/week @ 2021-07-30 230/week @ 2021-08-06 125/week @ 2021-08-13 166/week @ 2021-08-20 35/week @ 2021-08-27 30/week @ 2021-09-03 169/week @ 2021-09-10 104/week @ 2021-09-17 45/week @ 2021-09-24 54/week @ 2021-10-01 123/week @ 2021-10-08

567 downloads per month
Used in 14 crates (2 directly)

MIT license

220KB
6K SLoC

C 6K SLoC // 0.1% comments Rust 393 SLoC // 0.0% comments PowerShell 35 SLoC // 0.4% comments

HttpMuncher: Rust Streaming HTTP parser

Build Status Build status Documentation

Rust wrapper for NodeJS http-parser library.

It's intended to be used as an HTTP/1.x protocol handler in Rust-based web servers.

Motivation

Why not write a brand new HTTP parser from scratch in Rust or just use an existing crate such as httparse?

Here's why:

  • NodeJS HTTP parser library is based on a full-featured and robust nginx's HTTP parser, and it's safe, fast, and lightweight by design;
  • It's compatible with HTTP/1.1, including upgrade connections and chunked responses;
  • I haven't found a decent HTTP parser that is capable of streamed parsing, i.e. the one that can eagerly use partial data that comes from a TCP socket;
  • Rust's FFI has little to no overhead;
  • In most cases, it's silly to reinvent the wheel;
  • It was a lot of fun trying to learn Rust along the way. :)

Usage

Add the library to your Cargo.toml dependencies section:

[dependencies]
http-muncher = "0.3"

Or, for the edge version:

[dependencies]
http-muncher = {git = "https://github.com/nbaksalyar/rust-streaming-http-parser"}

You can find usage example in examples/parser.rs (run it by executing cargo run --example parser) and in the library tests.

API documentation

You can find API docs here.

Alternative libraries

  • http-parser-rs - Rust port of NodeJS HTTP parser (without FFI usage).
  • httparse - pure Rust HTTP parser implementation.

License

The MIT License (MIT)

Copyright (c) 2015 Nikita Baksalyar <nikita.baksalyar@gmail.com>

Dependencies

~170KB