Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
push:
branches:
- master
- main

env:
RUST_BACKTRACE: 1
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
with:
components: clippy
- name: Run clippy
run: cargo clippy --all-targets --all-features
run: cargo clippy --all-targets --all-features -- -D warnings

miri:
name: Test with Miri
Expand Down Expand Up @@ -173,11 +173,11 @@ jobs:
sudo apt-get install -y qemu-user gcc-aarch64-linux-gnu

- name: Build tests
run: cargo build --tests --target aarch64-unknown-linux-gnu
run: cargo test --no-run --target aarch64-unknown-linux-gnu --message-format=json | jq -r 'select(.executable != null) | .executable' > test-binaries.txt

- name: Run tests with QEMU
run: |
test_binaries=$(find target/aarch64-unknown-linux-gnu/debug/deps/ -type f -executable -name 'httparse-*')
test_binaries=$(cat test-binaries.txt)
if [ -n "$test_binaries" ]; then
for test_binary in $test_binaries
do
Expand All @@ -186,4 +186,5 @@ jobs:
done
else
echo "No test binaries found."
exit 1
fi
8 changes: 4 additions & 4 deletions .github/workflows/cibench.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI Benchmarks
on:
pull_request:
branches: [master]
branches: [main]

env:
CARGO_TERM_COLOR: always
Expand All @@ -25,7 +25,7 @@ jobs:

- name: Run benchmarks (master)
run: |
git checkout master
git checkout main
cargo bench --bench parse -- --save-baseline master

- name: Run benchmarks (PR)
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:

- name: Run benchmarks (master)
run: |
git checkout master
git checkout main
cargo bench --bench parse -- --save-baseline master-${{ matrix.feature }}

- name: Run benchmarks (PR)
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:

- name: Run benchmarks (master)
run: |
git checkout master
git checkout main
cargo bench --bench parse -- --save-baseline master-aarch64-${{ matrix.feature }}

- name: Run benchmarks (PR)
Expand Down
48 changes: 48 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Changes

## [2.2.0] - 2026-09-28

* Header names longer than 16 bytes are matched with SSE4.2 or AVX2 on x86

* Response reason phrases longer than 8 bytes are matched with SIMD

* `Request::parse_with_state` is fully resumable: every part of the request
line, including the method and leading empty lines, continues where the
previous `Partial` result stopped instead of being rescanned

* Add `Response::parse_with_state`, a resumable status line parser.
`Request::parse` and `Response::parse` are kept for compatibility

* Multiple spaces between the method and the path are accepted for every
method, not only `GET` and `POST`

* A bare CR before the request or status line is rejected when the input is
split right after it

* `parse_chunk_size` rejects control characters other than HTAB in chunk
extensions. Previously any octet was accepted, so a bare LF inside an
extension could be treated as the line end by other parsers (request
smuggling)

* Header parsing resumed after a `Partial` result that ended right after a
`\r` no longer accepts a bare CR (e.g. `X: a\rb\r\n` split after the `\r`
produced the value `"a\rb"`)

* `Request::parse_with_state` no longer fails with `Error::Token` when the
input is split right after the space following the request path

* `parse_chunk_size` rejects a chunk size line without digits (e.g. `\r\n` or
`;ext\r\n`), which was accepted as the last chunk

* `Request::parse_with_state` and `Header::parse_with_state` return an error
for an invalid `State` instead of panicking or returning stale positions

* `Response::parse` no longer skips empty lines between the version and the
status code (e.g. `HTTP/1.1\r\n 200 OK`)

* `HeaderParsed::Eof` holds the position in the buffer, like
`HeaderParsed::Header`, instead of the length of the final empty line. This
only differs when `State` is not reset between headers

* Rewrite API docs and README for the fork's API; hide the benchmark-only
`parse_method` and `parse_uri` from docs
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "ntex-httparse"
version = "2.1.0"
version = "2.2.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Sean McArthur <sean@seanmonstar.com>"]
license = "MIT OR Apache-2.0"
description = "A tiny, safe, speedy, zero-copy HTTP/1.x parser."
repository = "https://github.com/fafhrd91/httparse"
documentation = "https://docs.rs/httparse"
documentation = "https://docs.rs/ntex-httparse"
readme = "README.md"
keywords = ["http", "parser", "no_std"]
categories = ["network-programming", "no-std", "parser-implementations", "web-programming"]
Expand Down
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
# httparse
# ntex-httparse

[![crates.io](https://img.shields.io/crates/v/ntex-httparse.svg)](https://crates.io/crates/ntex-httparse)
[![Released API docs](https://docs.rs/ntex-httparse/badge.svg)](https://docs.rs/ntex-httparse)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE-MIT)
[![CI](https://github.com/fafhrd91/ntex-httparse/workflows/CI/badge.svg)](https://github.com/fafhrd91/ntex-httparse/actions?query=workflow%3ACI)
[![CI](https://github.com/fafhrd91/httparse/actions/workflows/ci.yml/badge.svg)](https://github.com/fafhrd91/httparse/actions/workflows/ci.yml)

A push parser for the HTTP 1.x protocol. Avoids allocations. No copy. **Fast.**
A push parser for the HTTP 1.x protocol, used by [ntex](https://crates.io/crates/ntex).
Fork of [httparse](https://crates.io/crates/httparse). Avoids allocations. No copy. **Fast.**

Works with `no_std`, simply disable the `std` Cargo feature.

[Changelog](https://github.com/fafhrd91/ntex-httparse/releases)
[Changelog](./CHANGES.md)

## Usage

The request line and headers are parsed separately. Parsed parts are
returned as positions into the buffer.

```rust
let mut headers = [httparse::EMPTY_HEADER; 64];
let mut req = httparse::Request::new(&mut headers);
use ntex_httparse::{Header, HeaderParsed, Request, Status};

let mut req = Request::default();
let buf = b"GET /index.html HTTP/1.1\r\nHost";
assert!(req.parse(buf)?.is_partial());
let mut pos = req.parse(buf)?.unwrap();
assert_eq!(&buf[req.path.start..req.path.end], b"/index.html");

// a partial request, so we try again once we have more data
let mut header = Header::default();
// a partial header, so we try again once we have more data
assert!(header.parse(&buf[pos..])?.is_partial());

let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n";
assert!(req.parse(buf)?.is_complete());
while let Status::Complete(parsed) = header.parse(&buf[pos..])? {
match parsed {
HeaderParsed::Header(len) => pos += len,
HeaderParsed::Eof(len) => {
pos += len;
break;
}
}
}
assert_eq!(pos, buf.len());
```

## License
Expand Down
Loading
Loading