Skip to content

HTTP parser extracted from nodejs/llhttp for IREE use

License

Notifications You must be signed in to change notification settings

iree-org/llhttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

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

  • Upstream Repository: https://github.com/nodejs/llhttp
  • Upstream Version: v9.3.0
  • Upstream Commit: release/v9.3.0
  • Upstream Date: 2025-05-23
  • License: MIT - see LICENSE

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)
int on_url(llhttp_t* parser, const char* at, size_t length) {
  printf("URL: %.*s\n", (int)length, at);
  return 0;
}

int on_header_field(llhttp_t* parser, const char* at, size_t length) {
  printf("Header: %.*s\n", (int)length, at);
  return 0;
}

int main() {
  llhttp_t parser;
  llhttp_settings_t settings;

  llhttp_settings_init(&settings);
  settings.on_url = on_url;
  settings.on_header_field = on_header_field;

  llhttp_init(&parser, HTTP_REQUEST, &settings);

  const char* request = "GET /hello HTTP/1.1\r\nHost: example.com\r\n\r\n";
  enum llhttp_errno err = llhttp_execute(&parser, request, strlen(request));

  if (err != HPE_OK) {
    fprintf(stderr, "Parse error: %s\n", llhttp_errno_name(err));
    return 1;
  }
  return 0;
}

Building

Bazel (IREE)

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

CMake

add_library(llhttp
  src/llhttp.c
  src/api.c
  src/http.c
)
target_include_directories(llhttp PUBLIC include)

Local Patches

(none)

About

HTTP parser extracted from nodejs/llhttp for IREE use

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages