<commit_before># HttpMuncher: Rust Streaming HTTP parser

![Build Status](https://travis-ci.org/nbaksalyar/rust-streaming-http-parser.svg?branch=master)

Rust wrapper for Joyent's [http-parser](https://github.com/joyent/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](https://github.com/seanmonstar/httparse)**?

Here's why:

* Joyent's library is based on a full-featured and robust [nginx](http://nginx.org)'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.1.0"

Or, for the edge version:

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

And then you can use it this way:

```Rust
extern crate http_muncher;

// Include the 2 main public interfaces of the crate
use http_muncher::{Parser, ParserHandler};

// Now let's define a new listener for parser events:
struct MyHandler;
impl ParserHandler for MyHandler {
<commit_msg>Fix typo in readme<commit_after># HttpMuncher: Rust Streaming HTTP parser

![Build Status](https://travis-ci.org/nbaksalyar/rust-streaming-http-parser.svg?branch=master)

Rust wrapper for Joyent's [http-parser](https://github.com/joyent/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](https://github.com/seanmonstar/httparse)**?

Here's why:

* Joyent's library is based on a full-featured and robust [nginx](http://nginx.org)'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.1.0"

Or, for the edge version:

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

And then you can use it this way:

```Rust
extern crate http_muncher;

// Include the 2 main public interfaces of the crate
use http_muncher::{Parser, ParserHandler};

// Now let's define a new listener for parser events:
struct MyHandler;
impl ParserHandler for MyHandler {

{'fraction_non_alphanumeric': 0.09640470887686924, 'fraction_numerical': 0.004454342984409799, 'mean_word_length': 4.467826086956522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1283482', 'n_tokens_mistral': 1006, 'n_tokens_neox': 939, 'n_words': 399}