xocomil
A lightweight, zero-allocation HTTP/1.1 request parser and response writer for Rust.
Xocomil parses requests by borrowing directly from the caller's read buffer and serializes response headers to a stack buffer -- no heap allocations on the hot path. Designed for use in embedded servers, proxies, and anywhere allocation discipline matters.
Features
- Zero-copy parsing -- request method, path, and headers borrow from your buffer
- Zero heap allocations -- parsing and response writing stay on the stack
- O(1) header lookup -- known headers (Host, Content-Type, etc.) use a compile-time slot table
- SIMD-accelerated validation -- SSE2/AVX2 character class checks where available, with scalar fallback
- Streaming body support -- pipe chunked or content-length bodies from a
BufReadto anyWrite - In-place chunked decoding -- decode Transfer-Encoding: chunked without extra buffers
- Compile-time tuning -- const generics control max headers, body limits, and buffer sizes
- Hardened -- rejects request smuggling vectors (duplicate Content-Length, conflicting TE+CL, CRLF injection)
Quick start
use Request;
use RequestHeader;
let raw = b"GET /index.html HTTP/1.1\r\nHost: example.com\r\n\r\n";
let req = parse.unwrap;
assert_eq!;
assert_eq!;
Writing responses
use ;
use Response;
let mut output = Vecnew;
new
.header.unwrap
.write
.unwrap;
Reading from a stream
use Request;
let raw = b"POST / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5\r\n\r\nhello";
let mut buf = ;
let rr = read.unwrap;
let mut body = Vecnew;
rr.stream_body_to.unwrap;
assert_eq!;
Unsupported methods
CONNECT and TRACE are intentionally omitted:
- TRACE enables cross-site tracing (XST) attacks
- CONNECT changes connection semantics (proxy tunneling) and is out of scope for a request parser
Minimum Supported Rust Version
Rust 1.85 (edition 2024).
License
MIT -- see LICENSE for details.