Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

llhttp

HTTP request/response parser extracted from nodejs/llhttp.

This is the HTTP parser used by Node.js - battle-tested against billions of requests. It's a pure C library with no dependencies, designed for high-performance HTTP parsing with a callback-based, zero-copy API.

Source

Features

  • Pure C, zero dependencies
  • Callback-based, zero-copy parsing (pointers into your buffer)
  • Incremental parsing (feed bytes as they arrive)
  • Handles all HTTP/1.x edge cases:
    • Chunked transfer encoding
    • Keep-alive detection
    • Header line folding
    • Request pipelining
    • Content-Length vs Transfer-Encoding
  • ~20KB compiled
  • Extensively tested (Node.js test suite)

Updating

  1. Check for new releases at https://github.com/nodejs/llhttp/releases

  2. Download the release tarball:

    gh release download release/vX.Y.Z --repo nodejs/llhttp --archive=tar.gz -D /tmp
    cd /tmp && tar -xzf nodejs-llhttp-*.tar.gz
  3. Copy the files:

    cp /tmp/llhttp-release-vX.Y.Z/include/llhttp.h include/
    cp /tmp/llhttp-release-vX.Y.Z/src/*.c src/
    cp /tmp/llhttp-release-vX.Y.Z/LICENSE-MIT LICENSE
  4. Update this README with the new version, commit hash, and date.

  5. Test the build in IREE.

Contents

include/

  • llhttp.h - Public API header with types, callbacks, and function declarations

src/

  • llhttp.c - Core parser state machine (auto-generated)
  • api.c - User-facing API functions (init, execute, settings)
  • http.c - HTTP-specific helpers (keep-alive, upgrade detection)

Usage

#include"llhttp.h"// Callbacks receive pointers into your buffer (zero-copy)inton_url(llhttp_t*parser, constchar*at, size_tlength) {
printf("URL: %.*s\n", (int)length, at);
return0;
}
inton_header_field(llhttp_t*parser, constchar*at, size_tlength) {
printf("Header: %.*s\n", (int)length, at);
return0;
}
intmain() {
llhttp_tparser;
llhttp_settings_tsettings;
llhttp_settings_init(&settings);
settings.on_url=on_url;
settings.on_header_field=on_header_field;
llhttp_init(&parser, HTTP_REQUEST, &settings);
constchar*request="GET /hello HTTP/1.1\r\nHost: example.com\r\n\r\n";
enumllhttp_errnoerr=llhttp_execute(&parser, request, strlen(request));
if (err!=HPE_OK) {
fprintf(stderr, "Parse error: %s\n", llhttp_errno_name(err));
return1;
}
return0;
}

Building

Bazel (IREE)

cc_library(
name="llhttp",
srcs=glob(["src/*.c"]),
hdrs= ["include/llhttp.h"],
includes= ["include"],
visibility= ["//visibility:public"],
)

CMake

add_library(llhttpsrc/llhttp.csrc/api.csrc/http.c
)
target_include_directories(llhttpPUBLICinclude)

Local Patches

(none)

About

HTTP parser extracted from nodejs/llhttp for IREE use

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages