wire 1.0.1
High-performance, zero-allocation HTTP parser for D - wrapping llhttp
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Wire
High-performance, zero-allocation HTTP parser for D.
Built on llhttp, the HTTP parser that powers Node.js.
Overview
Wire provides a @nogc nothrow HTTP/1.x parser with zero heap allocations. All string data is accessed via StringView slices into the original request buffer.
Key characteristics:
- Zero GC allocations during parsing
- Complete
@nogc nothrowAPI - 64-byte aligned structures for cache efficiency
- Thread-local parser pool with automatic reuse
Installation
Add to your dub.json:
"dependencies": {
"wire": "~>1.0.0"
}
Or with dub.sdl:
dependency "wire" version="~>1.0.0"
Building from Source
git clone https://github.com/federikowsky/Wire.git
cd Wire
make # Build and run tests
make lib # Build static library only
Quick Start
import wire;
void handleRequest(const(ubyte)[] data) @nogc nothrow {
auto req = parseHTTP(data);
if (!req) return; // Parse error
auto method = req.getMethod(); // "GET"
auto path = req.getPath(); // "/api/users"
auto host = req.getHeader("Host"); // "example.com"
auto page = req.getQueryParam("page");
if (req.shouldKeepAlive()) {
// Reuse connection
}
}
API Reference
Parsing
auto parseHTTP(const(ubyte)[] data) @nogc nothrow;
Returns a ParserWrapper with RAII cleanup. The parser is automatically returned to the thread-local pool on scope exit.
Request Methods
| Method | Returns | Description |
|---|---|---|
getMethod() | StringView | HTTP method |
getPath() | StringView | Request path |
getQuery() | StringView | Query string (without ?) |
getHeader(name) | StringView | Header value (case-insensitive) |
getQueryParam(name) | StringView | Query parameter value |
getBody() | StringView | Request body |
shouldKeepAlive() | bool | Connection keep-alive status |
isUpgrade() | bool | WebSocket upgrade request |
getErrorCode() | int | Error code (0 = success) |
All methods are @nogc nothrow and return zero-copy views.
Header Iteration
foreach (header; req.getHeaders()) {
writeln(header.name, ": ", header.value);
}
Performance
Benchmarked on Apple M2 with LDC 1.41:
| Request Type | Size | Parse Time | Throughput |
|---|---|---|---|
| Simple GET | 37 B | 7 μs | 5 MB/s |
| Browser (Chrome) | 1.0 KB | 1 μs | 983 MB/s |
| REST API + JWT | 1.5 KB | 1 μs | 1,442 MB/s |
| Stripe Webhook | 2.1 KB | 1 μs | 2,023 MB/s |
Memory usage:
- Per thread: ~1 KB (parser pool)
- Per request: 0 bytes (zero allocation)
- Header limit: 64 headers
Building
Requirements
- D Compiler: LDC 1.35+ (recommended) or DMD 2.105+
- C Compiler: clang or gcc (C99)
Make Targets
| Target | Description |
|---|---|
make | Build and run tests |
make lib | Build libwire.a |
make test-verbose | Tests with timing |
make debug | Debug build |
make clean | Clean artifacts |
Documentation
- Technical Specifications — Complete API reference
- llhttp — Underlying parser
Contributing
Contributions are welcome. Please ensure:
- All code maintains
@nogc nothrowcompatibility - Tests pass (
make test) - Code follows D style guidelines
License
MIT License — see LICENSE for details.
- 1.0.1 released a day ago
- federikowsky/Wire
- github.com/federikowsky/Wire
- MIT
- Copyright 2024 Federico Filippi
- Authors:
- Dependencies:
- none
- Versions:
-
Show all 4 versions1.0.1 2025-Dec-07 1.0.0 2025-Dec-07 ~main 2025-Dec-07 ~copilot/translate-italian-comments 2025-Dec-02 - Download Stats:
-
-
2 downloads today
-
7 downloads this week
-
7 downloads this month
-
7 downloads total
-
- Score:
- 0.1
- Short URL:
- wire.dub.pm