h2o/picohttpparser logo

h2o/picohttpparser

Free

tiny HTTP parser written in C (used in HTTP::Parser::XS et al.)

FreeFree tier
Type
Open Source

About h2o/picohttpparser

PicoHTTPParser is a tiny, primitive, and fast HTTP request/response parser written in C. Unlike most parsers, it is stateless and does no memory allocation: it accepts a buffer pointer and an output structure, then sets pointers in the output to reference the relevant portions of the buffer. This design makes it extremely lightweight and suitable for high-performance applications. The library exposes four functions: phr_parse_request, phr_parse_response, phr_parse_headers, and phr_decode_chunked. It is widely deployed in the Perl ecosystem through modules like Plack, Starman, Starlet, and Furl, and also serves as the HTTP/1 parser in the H2O web server. The software is dual-licensed under the Perl License or the MIT License.

Key Features

Tiny and fast HTTP request/response parser
Stateless – does not allocate memory by itself
Pointer-based output – sets pointers into the provided buffer
Supports parsing of HTTP request line, response line, and headers
Includes chunked transfer decoding via phr_decode_chunked
Dual-licensed under Perl License and MIT License
Widely used in Perl web frameworks (Plack, Starman, Starlet, Furl) and the H2O server

Pros & Cons

Pros
  • Minimal footprint and very fast parsing
  • No dynamic memory allocation (zero-copy design)
  • Proven in production across many Perl applications and H2O
  • Simple API with only four functions
  • Dual-licensed for flexible integration
Cons
  • Only parses request/response line and headers – does not parse the HTTP body
  • Requires manual handling of chunked encoding via separate decoder
  • No URL parsing or header value decomposition – caller must process raw strings
  • Minimal error reporting; returns simple integer status
  • Not a full-featured HTTP library; intended as a building block

Best For

Parsing HTTP requests and responses in C-based web servers or proxiesBuilding lightweight HTTP parsing in Perl XS modulesEmbedding HTTP parsing in performance-sensitive applicationsEducational example of a minimal HTTP parser

FAQ

What does PicoHTTPParser parse?
It parses HTTP request and response start lines (method, path, version) and headers. It also provides a function for decoding chunked transfer encoding. It does not parse the HTTP body or URL.
Does PicoHTTPParser allocate memory?
No, it is stateless and does no memory allocation. It takes a buffer pointer and an output structure, then sets pointers in the output to reference the relevant parts of the buffer.