$ show nodejs/llhttp
llhttp is a high-performance HTTP/1.1 parser written in TypeScript that generates optimized C source code via the llparse state machine compiler. It is the parser used by Node.js for handling HTTP requests and responses. The core logic is defined as a finite state machine in TypeScript, which is then compiled to C for maximum performance, achieving around 156% faster parsing than the legacy http_parser. The architecture separates the HTTP line parsing (method, URL, version) from header and chunked body parsing, with a dedicated URL state machine. The parser supports both request and response modes, configurable lenient parsing for non-compliant clients, and exposes callbacks for message begin/end, headers, body, and chunk events. It is distributed as both a native C library and a WebAssembly module, making it usable in diverse environments.
The LLM identified 3 files worth highlighting for reuse:
Defines all HTTP constants including methods, status codes, error codes, flags, token character sets (ALPHA, DIGIT, TOKEN, etc.), and header state mappings. This module is purely declarative, has no internal dependencies, and can be extracted as a standalone HTTP constants library for any HTTP implementation. It demonstrates deep knowledge of RFC specifications and provides a comprehensive reference for HTTP parsing.
Implements a URL parsing state machine using the llparse framework. It handles absolute URLs with schema, host (including IPv6, port, auth), path, query string, and fragment. The parser is self-contained and can be reused independently from the HTTP parser for URL validation or splitting. The separation of spans for schema, host, path, query, and fragment enables fine-grained callback support.
The public C header that defines the llhttp_t parser struct, callback types (llhttp_data_cb, llhttp_cb), and configuration functions for lenient parsing modes. It provides a clean, reusable interface for embedding the parser in any C/C++ project. The callback-based design is a well-proven pattern for parsing libraries, and the header's extensive documentation makes it an excellent reference for similar API designs.