httpio – async HTTP/1.1 over any transport
httpio is a low-level, async HTTP/1.1 client and server library that is agnostic to the underlying transport.
You bring any AsyncBufRead / AsyncWrite streams (plain TCP, TLS-over-TCP, in‑memory pipes, custom tunnels) and httpio handles the HTTP protocol: request building, parsing, transfer encodings, compression and multipart bodies.
Note: replace
httpiowith the actual crate name you publish to crates.io.
Why this crate?
- Transport-agnostic by design: works with bare TCP, Rustls, custom TLS stacks, proxies, SSH tunnels, or test in‑memory streams – anything that implements
AsyncBufRead + UnpinandAsyncWrite + Unpin. - Runtime-agnostic: does not depend on any specific async runtime. You can use
async-std,tokio,smol,async-foundation, or your own executor. - Client & Server: Provides low-level primitives for building both HTTP clients and servers.
- Focused HTTP wire layer: no cookie jars, redirect logic, or JSON helpers; this is a precise HTTP/1.1 core meant for building higher-level clients or specialized tools.
- Robust body handling: supports
Content-Encoding(gzip/deflate),Transfer-Encoding(chunked, gzip/deflate) and multipart bodies. - Connection pooling: built-in connection pool with idle timeouts for reusing HTTP/1.1 keep-alive connections.
- Character set aware: response bodies can be decoded to
Stringaccording to the charset advertised by the server (with sensible defaults). - Structured logging: pluggable logger so you can trace requests and responses without sprinkling manual
println!calls.
If you want a small, composable HTTP core that you can plug into your own networking and TLS stack, this crate is for you.
Examples included: Check the
examples/directory to see how to integrate Rustls for TLS and flate2 for Gzip/Deflate compression.
Features
-
HTTP/1.1 client
- Start-line and header construction via
HttpRequestBuilder. HttpConnectionabstraction over any async reader/writer pair.- Connection reuse with
HttpConnectionPool.
- Start-line and header construction via
-
HTTP/1.1 server
HttpServerConnectionto read requests and send responses over any async stream.- Supports building simple HTTP/HTTPS servers.
-
Transport flexibility
- Generic over
R: AsyncBufRead + UnpinandW: AsyncWrite + Unpin. - Works with:
- plain
TcpStream(from any runtime), - TLS streams (e.g. Rustls, native-tls, custom TLS 1.2 implementation),
- any other async stream pair (e.g. in-memory for tests).
- plain
- Generic over
-
Body & encoding support
HttpBodyenum for:- empty bodies,
- raw bytes,
- multipart bodies (
HttpMultipartBody).
- Handles:
Content-Length,Transfer-Encoding: chunked,Content-Encoding: gzip/deflate(pluggable backend),- combinations of transfer and content encodings (decoded in the correct order).
-
Compression Support
- Compression-agnostic: No bundled compression library; you choose the implementation.
- Pluggable: Implement
CompressionDecoderto support gzip, deflate, brotli, zstd, etc. - Zero default dependencies: Keeps the crate small and compile times fast.
- Customizable: Register your provider via
set_compression_provider.
-
Multipart support
- Parses multipart bodies based on boundary and subtype.
- Exposes parts via
HttpMultipartBodyandHttpBodyPart.
-
Headers & utilities
HttpHeaderListwith helpers for:- content length,
- transfer encodings,
- content encodings,
- multipart boundary & subtype,
- charset detection.
- Constants for common header names (e.g.
HOST,USER_AGENT,ACCEPT,ACCEPT_ENCODING,TE, …).
Quick start
Add this to your Cargo.toml:
[]
= "0.1" # replace with the actual crate name and version
= "0.3"
Example: simple GET over plain TCP
This example uses a generic async TCP stream. It assumes you already have a connected stream that implements AsyncRead + AsyncWrite.
use BufReader;
use ;
use CharSet;
use HttpBody;
use HttpRequestMethod;
use HttpVersion;
use HttpConnection;
use HttpHeaderList;
use http_header_field_name;
async
You are free to choose how sockets are created and which runtime you use; the HTTP layer only cares about the async reader/writer.
Example: plugging in TLS (Rustls)
Because the crate is transport-agnostic, TLS is just a matter of wrapping your TCP stream with a TLS stream that still implements AsyncBufRead / AsyncWrite, then passing it to HttpConnection.
See
examples/client_tls/for a full working example usingrustlsandfutures-rustls.
use BufReader;
use HttpConnection;
use HttpVersion;
use HttpHeaderList;
async
The library does not bundle a specific TLS stack; instead it embraces the async traits so you can choose Rustls, native-tls, a custom TLS 1.2 crate, or no TLS at all.
Server Support
The library now includes basic server-side functionality via HttpServerConnection. You can use it to build transport-agnostic HTTP servers.
Example: Simple Server
See
examples/server/for a complete example supporting both HTTP and HTTPS usingsmolandrustls.
use HttpServerConnection;
use HttpResponse;
use HttpStatusCode;
use HttpBody;
async
Compression
This library is compression-agnostic. It does not bundle any compression library by default to keep the core lightweight and dependencies minimal.
See
examples/client/main.rsfor a complete example of integratingflate2.
To support Content-Encoding: gzip, deflate, br, or zstd, you must provide an implementation of the CompressionDecoder trait. This design allows you to:
- Choose your preferred compression crates (e.g.
flate2,async-compression,brotli). - Support only the algorithms you need.
- Avoid compiling unused compression logic.
Providing a compression implementation
You can implement the CompressionDecoder trait and register it globally at runtime start-up.
use CompressionDecoder;
use set_compression_provider;
use ContentEncoding;
use ;
use HttpError;
// Example using flate2 (you need to add flate2 to your dependencies)
// use flate2::read::{GzDecoder, ZlibDecoder};
// use std::io::Read;
;
// In your main initialization code:
Design goals & non-goals
Goals
- Be a small, composable building block for HTTP/1.1 over async transports.
- Make it easy to:
- plug in different runtimes,
- plug in different TLS implementations,
- build higher-level clients with their own policies (retries, redirects, auth, JSON, etc.).
- Provide correct handling of encodings and multipart without hiding the underlying protocol.
Non-goals
- Compete with full-featured clients like
reqwestorsurf. - Provide HTTP/2 / HTTP/3 support (HTTP/1.1 only for now).
- Implement high-level features such as:
- cookie management,
- redirects,
- authentication flows,
- automatic JSON (de)serialization.
You are expected to build those features on top of this crate, with full control.
Status
- HTTP/1.1 client: stable for typical use (GET/POST, streaming bodies, gzip/deflate, chunked).
- HTTP/1.1 server: basic support available.
- TLS: supported via external crates (see examples).
- API: may still evolve before
1.0as more real-world use cases are integrated.
Feedback and issues are very welcome.
License
This project is licensed under either of:
- MIT license
- Apache License, Version 2.0
at your option.