Fast HTTP/1.1 & HTTP/1.0 parser. Powered by Zig ⚡
- Cross-platform SIMD vectorization through Zig's
@Vector
, - Streaming first; can be easily integrated to event loops,
- Handles partial requests,
- Never allocates and never copies.
- Similar API to picohttpparser; can be swapped in smoothly.
Benchmarks can be found under bench/
folder, they can either be run with hyperfine or poop.
Here are the comparison of 3 parser libraries (hparse, httparse and picohttpparser) via hyperfine, visualized by Claude 3.7 Sonnet.
const buffer: []const u8 = "GET /hello-world HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n";
// initialize with default values
var method: Method = .unknown;
var path: ?[]const u8 = null;
var http_version: Version = .@"1.0";
var headers: [32]Header = undefined;
var header_count: usize = 0;
// parse the request
_ = try hparse.parseRequest(buffer[0..], &method, &path, &http_version, &headers, &header_count);
Install via Zig package manager (Copy the full SHA of latest commit hash from GitHub):
zig fetch --save https://github.com/nikneym/hparse/archive/<latest-commit-hash>.tar.gz
In your build
function at build.zig
, make sure your build step and source files are aware of the module:
const dep_opts = .{ .target = target, .optimize = optimize };
const hparse_dep = b.dependency("hparse", dep_opts);
const hparse_module = hparse_dep.module("hparse");
exe_mod.addImport("hparse", hparse_module);
This project wouldn't be possible without these other projects and posts:
- h2o/picohttpparser
- seanmonstar/httparse
- SIMD with Zig by Karl Seguin
- SWAR explained: parsing eight digits by Daniel Lemire
- Bit Twiddling Hacks by Sean Eron Anderson
MIT.