seanmonstar/httparse

A push parser for the HTTP 1

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2

httparse

A push parser for the HTTP 1.x protocol. Avoids allocations. No copy. Fast.

Works with no_std, simply disable the std Cargo feature.

Changelog

Usage

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Issues

Collection of the latest Issues

errantmind

errantmind

Comment Icon8

Hello, first, thanks for making this tool.

I wanted to point out your benchmark is a bit unfair as you compare httparse sse4 against picohttpparser without sse4. The reason picohttpparser doesn't have sse4 is because your dependency 'pico-sys' does not compile picohttpparser with sse4 enabled.

Your benchmark showed a ~60% improvement in performance for 'bench_pico' once sse4 was enabled in the underlying crate.

I forked the underlying crate 'pico-sys' and made a few modifications if you want to verify my results:

https://github.com/errantmind/rust-pico-sys

clouduol

clouduol

Comment Icon3

In the header name map, index 34 is false. So when parsing headers, the program will return Error::HeaderName when meeting double quotes(ascii number is 34) . However, bouble quotes in headers can be parsed correctly in chrome. Is this intentional or a bug?

Test Example:

Chris-Barrett-FW

Chris-Barrett-FW

Comment Icon0

If the HTTP message begins with whitespace, the resulting error is "invalid HTTP version". This felt misleading, or at least less helpful than it could be, since the version (HTTP/1.1) in the start-line was fine. If the message could instead either, ideally call out leading whitespace (as it may be subtle to spot), or at least instead say something like "invalid start-line", or "doesn't match HTTP format", or similar, I think it could help save people some time in tracking down this particular issue.

EkardNT

EkardNT

Comment Icon5

I am building a HTTP server on top of tokio that needs to perform minimal memory allocations per client TCP connection, regardless of how many HTTP requests are received through the connection. Therefore I have chosen to use a fixed-size circular buffer to store the raw request data read from the wire, and now I am trying to use httparse to parse the request information. The problem I have run into is that the Request.parse function takes in a single &[u8], but because I'm using a circular buffer I have two slices - one for the bytes in the remainder of the buffer, and one (optionally) for the bytes which wrapped around to the front of the buffer. This two-buffer approach works very well with vectored IO reads, but not so well so far with httparse.

At first I was hoping I that httparse's Request type would be persistent, so I could call parse in turn for both of the slices. But that appears to not be how the API works - it expects the one slice to have all the data, and when you call it a second time the same data should still be present, only with more added to the end.

Consequently, the only way I can find to use httparse today is to perform a copy of the data from the circular buffer into a secondary contiguous buffer. But the cost of such copying is potentially significant and I'd prefer to avoid it where possible. How feasible would it be to add some sort of parse_vectored function to httpparse which takes a &[std::io::IoSlice]?

MOZGIII

MOZGIII

Comment Icon0

Hello, I'm trying to use this crate to implement a parser, but I'm having difficulties implementing response reading loop.

Here's my crate's code: https://github.com/MOZGIII/http-proxy-client-async And I'm having issues with this section in particular: https://github.com/MOZGIII/http-proxy-client-async/blob/d5d29ec06c5cd912e17ec358ee77860c7e8b4f61/src/http.rs#L39-L54

The issue is with borrowing the buf:

Since this crate has a kind of unique API, how would you recommend solving this issue?

Nurrl

Nurrl

Comment Icon0

This crate could implement the parsing mechanism for the http crate, which is already used by everyone, this would be really cool, so this lib serializes and deserializes http::Request and http::Response.

seanmonstar

seanmonstar

Comment Icon3

These were added in #40, but understanding exactly what is happening is difficult. It'd be best to document what in the world is happening :)

jethrogb

jethrogb

Comment Icon8

I would like to build a function

that reads as much from stream into buf as necessary to get a Complete return from Request::parse. This turns out to not be trivial and require lots of extra allocations and work.

Here's what I came up with:

The main issues are having to allocate a new array of temporary headers for every iteration, and having to parse the succesful result twice.

I think this is partially Rust's fault, but also partially httparse for having a not so great API. For example, the lifetime of everything is fixed upon Request creation, so that a parse failure doesn't release the borrow of the input buffer.

Versions

Find the latest versions by id

v1.7.1 - Apr 26, 2022

Fixes

v1.7.0 - Apr 11, 2022

Features

Fixes

New Contributors ❤️

v1.6.0 - Feb 08, 2022

Features

Fixes

New Contributors

v1.5.1 - Aug 19, 2021

v1.5.0 - Aug 18, 2021

  • FEAT: Adds parse_with_uninit_headers() functions for Request and Response, that allow passing a slice of MaybeUninit headers. Because of the newer std type, the Minimum Support Rust Version has been increased to 1.36.0.

v1.4.0 - Apr 16, 2021

  • FEAT: Adds ParserConfig, a new type to allow making some parsing rules more or less strict, or otherwise customize the parsing.
  • FEAT: Adds ParserConfig::allow_spaces_after_header_name_in_responses(bool), which when set to true, will allow skipping spaces between a header name and the colon. The specification requires that to be illegal in most cases, but says proxies should accept and remove those spaces.

v1.3.5 - Feb 01, 2021

  • FIX: Set Response.reason to an empty string if obs-text is found in the reason-phrase.
  • PERF: Fix faster next_8 to work when there are exactly 8 bytes left.

v1.3.4 - Jul 03, 2019

  • FIX: Allow backslash (\) characters when parsing request-target.

v1.3.3 - Sep 27, 2018

  • FIX: Allow {|}^` characters when parsing request-target.
  • FIX: Strip trailing whitespace from header values.
  • PERF: Improve selection of AVX2 and SSE4.2 features if both are available.

v1.3.2 - Sep 27, 2018

  • FIX fix incorrect response parsing when reason-phrase is missing.

v1.3.1 - Jun 23, 2018

  • FIX fix compile error of AVX2 functions on 32bit targets.

v1.3.0 - Jun 23, 2018

  • PERF: enable both compile-time and run-time checks for SSE4.2 and AVX2 instructions, and greatly improve parsing speed when available. See #40

v1.2.5 - Jun 23, 2018

  • FIX: allow HTAB bytes in header values

v1.2.4 - Jun 23, 2018

  • FIX: look for invalid version even if less than 8 bytes long, instead of returning Status::Partial

v1.2.3 - Jun 23, 2018

  • PERF: switch header parsing to use lookup tables
  • PERF: remove unused field when debug assertions aren't enabled

v1.2.2 - Apr 19, 2017

  • PERF Reduce EOF checks in internal parse_version

v1.2.1 - Dec 04, 2016

  • FIXED: overflow when parsing chunked size hex digit that was too big
  • FIXED: allow parsing of response that do not include a reason-phrase

v1.2.0 - Nov 07, 2016

  • NEW: added std cargo feature, on by default. Disable to use in no_std environments.
  • NEW: implement fmt::Display and std::error::Error for httparse::Error.
  • NEW: Relicense under dual license of MIT or Apache-2.0.

v1.1.2 - Nov 07, 2016

  • FIX: skip empty lines before the start of a request or response

v1.1.1 - Nov 07, 2016

  • FIX: Correctly return Error when method or path have illegal values

v1.1.0 - Nov 07, 2016

  • NEW: httparse::parse_chunk_size function added

v1.0.0 - Nov 07, 2016

  • NEW: httparse::Request and httparse::Response

Information - Updated Jun 19, 2022

Stars: 371
Forks: 80
Issues: 13

When you need to pretend you are a REST API, but you're really not

Facade is a Rust-based HTTP transformation layer to seamlessly convert REST calls into GraphQL calls for piecemeal API migrations

When you need to pretend you are a REST API, but you're really not

Rust helpers for serving HTTP GET and HEAD responses with

This crate supplies two ways to respond to HTTP GET and HEAD requests:

Rust helpers for serving HTTP GET and HEAD responses with

When you need to pretend you are a REST API, but you're really not

Vostok is a Rust-Based HTTP Transformation Layer To Seamlessly Convert REST Calls Into GraphQL Calls For Piecemeal API Migrations

When you need to pretend you are a REST API, but you're really not

Eve-rs is a middleware-based rust http framework which is inspired from ExpressJS framework

Let's create a demo application using eve-rs, using an intuative approach to get a better understanding of the framework

Eve-rs is a middleware-based rust http framework which is inspired from ExpressJS framework
Http

375

HTTP mocking for Rust!

Before upgrading, make sure to check out the rustfmt as a general code style

HTTP mocking for Rust!

Rust Urbit HTTP API

This library wraps the Urbit ship http interface exposing it as an easy-to-use Rust crate

Rust Urbit HTTP API

HTTP Server with Rust

Rust http server from scratch

HTTP Server with Rust

ehttp: a minimal Rust HTTP client for both native and WASM

If you want to do HTTP requests and are targetting both native and web (WASM), then this is the crate for you!

ehttp: a minimal Rust HTTP client for both native and WASM

Here lies my attempt to create a multi thread webserver based off of Rust and...

Here lies my attempt to create a multi thread webserver based off of Rust and using HTTP and TCP networking protocols :)

Here lies my attempt to create a multi thread webserver based off of Rust and...

rust-http-server

Multithread HTTP Server developed with Rust

rust-http-server
Facebook Instagram Twitter GitHub Dribbble
Privacy