Expand description
§xocomil
A lightweight, zero-allocation HTTP/1.1 request parser and response writer.
Supports the standard HTTP methods: GET, HEAD, POST, PUT, DELETE, PATCH, and OPTIONS. Request parsing borrows directly from the caller’s read buffer, and response headers are serialized to a stack buffer — no heap allocations on the hot path.
§Unsupported methods
CONNECT and TRACE are intentionally omitted:
- TRACE enables cross-site tracing (XST) attacks, allowing an
attacker to steal credentials from
AuthorizationorCookieheaders reflected in the response body. Most production servers disable it. - CONNECT requests proxy tunneling, which is out of scope for a request parser — it changes the connection semantics entirely (the server becomes a TCP relay).
If you need either method, parse the method bytes directly from the raw request line.
§Parsing requests
use xocomil::request::Request;
use xocomil::headers::RequestHeader;
let raw = b"GET /index.html HTTP/1.1\r\nHost: example.com\r\n\r\n";
let req: Request = Request::parse(raw).unwrap();
assert_eq!(req.path(), b"/index.html");
// Type-safe header lookup (zero-cost, static dispatch)
assert_eq!(req.header(RequestHeader::Host), Some(&b"example.com"[..]));
// Convert to &str on demand
assert_eq!(req.header_str("Host").unwrap(), Some("example.com"));§Writing responses
use xocomil::headers::{StatusCode, ResponseHeader};
use xocomil::response::Response;
let mut output = Vec::new();
Response::<16>::new(StatusCode::Ok)
.header(ResponseHeader::ContentType, b"text/plain").unwrap()
.write(&mut output, b"hello")
.unwrap();
let response = String::from_utf8(output).unwrap();
assert!(response.starts_with("HTTP/1.1 200 OK\r\n"));
assert!(response.ends_with("hello"));Re-exports§
pub use error::BodyErrorKind;pub use error::Error;pub use error::MediaErrorKind;pub use error::ParseErrorKind;pub use error::PctErrorKind;pub use error::ReadError;pub use error::ResponseErrorKind;
Modules§
- ascii
- HTTP-significant byte constants as a zero-cost
#[repr(u8)]enum. - body
- HTTP request body: zero-copy parsing, chunked decoding, and streaming.
- error
- Unified error type for all xocomil operations.
- headers
- HTTP header name types and the
HeaderNametrait. - media
- Parsing of
Content-Type(and other media-type) header values. - pct
- Percent-decoding for HTTP request targets and form-encoded values.
- query
- Iterator over
application/x-www-form-urlencodedname/value pairs. - request
- response