tiny HTTP parser written in C (used in HTTP::Parser::XS et al.)
tiny HTTP parser written in C (used in HTTP::Parser::XS et al.)
Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase, Shigeo Mitsunari
PicoHTTPParser is a tiny, primitive, fast HTTP request/response parser.
Unlike most parsers, it is stateless and does not allocate memory by itself. All it does is accept pointer to buffer and the output structure, and setups the pointers in the latter to point at the necessary portions of the buffer.
The code is widely deployed within Perl applications through popular modules that use it, including Plack, Starman, Starlet, Furl. It is also the HTTP/1 parser of H2O.
Check out [test.c] to find out how to use the parser.
The software is dual-licensed under the Perl License or the MIT License.
The library exposes four functions: phr_parse_request, phr_parse_response, phr_parse_headers, phr_decode_chunked.
The example below reads an HTTP request from socket sock using read(2), parses it using phr_parse_request, and prints the details.
…
phr_parse_response and phr_parse_headers provide similar interfaces as phr_parse_request. phr_parse_response parses an HTTP response, and phr_parse_headers parses the headers only.
The example below decodes incoming data in chunked-encoding. The data is decoded in-place.
…
The benchmark code is from fukamachi/fast-http@6b91103.
The internals of picohttpparser has been described to some extent in my blog entry.
No open issues yet, or sync has not completed.