A lightweight HTTP/1.1 library in C, built from the wire format up using only the C standard library and POSIX.
Built to understand HTTP/1.1 end-to-end without leaning on libcurl, nginx, or a framework as a black box. The goal is a small, readable codebase that maps cleanly onto the relevant sections of RFC 9110 and RFC 9112.
- Open-addressing hashmap with case-insensitive keys (for headers)
- Method parsing:
GET,HEAD,POST,PUT,DELETE,OPTIONS,PATCH - Request struct: method, URI, version, headers, body
- Response struct: status, reason, version, headers, body
- Request and response serialization to wire format
- Request parsing from a byte buffer (
Content-Lengthbodies) - Socket server loop
-
Transfer-Encoding: chunked - Persistent connections (
Connection: keep-alive) - Client-side request sending
- TLS (delegate to a reverse proxy)
- HTTP/2 or HTTP/3
- Async I/O — blocking sockets are sufficient for the learning scope
include/hashmap.h, src/hashmap.c open-addressing map, case-insensitive keys
include/http.h, src/http.c methods, request/response types, parse, serialize
src/main.c test driver exercising the library
Requires Meson and a C2x-capable compiler.
meson setup build
meson compile -C build
./build/lwhttp-test- Hashmap for headers. Header lookup is case-insensitive per RFC 9110 §5.1, and a request can carry dozens of headers. A small open-addressing map keeps lookup O(1) average and avoids per-lookup
strcasecmpscans. - Incremental parser API.
lw_request_parsereturns1when the buffer is incomplete so a caller can read more from a socket and retry, rather than forcing the whole request to be buffered before parsing begins. - C2x + warning level 3. Lets the compiler catch as much as possible at build time given the manual memory management.