Skip to content
/ hparse Public

Fastest HTTP parser in the west. Utilizes SIMD vectorization, supports streaming and never allocates. Powered by Zig ⚡

License

Notifications You must be signed in to change notification settings

nikneym/hparse

Repository files navigation

hparse

GitHub License GitHub Actions Workflow Status GitHub Actions Workflow Status GitHub Actions Workflow Status

Fast HTTP/1.1 & HTTP/1.0 parser. Powered by Zig ⚡

Features

  • 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

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.

Usage

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);

Installation

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);

Acknowledgements

This project wouldn't be possible without these other projects and posts:

License

MIT.

About

Fastest HTTP parser in the west. Utilizes SIMD vectorization, supports streaming and never allocates. Powered by Zig ⚡

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published