Skip to main content

Crate sutegi_http

Crate sutegi_http 

Source
Expand description

A minimal HTTP/1.1 server built directly on std::net.

No async runtime, no hyper, no tokio. Connections are handled by a fixed thread pool. This is deliberately small: it keeps the binary tiny and the request lifecycle trivial to reason about — for a human reading the source, or an agent reasoning about the running app.

Structs§

Request
A parsed HTTP request.
Response
An HTTP response.
SseSink
A flushing sink that formats Server-Sent Events (text/event-stream). Each call emits one event frame and flushes — exactly what LLM token streaming wants.
StreamSink
A flushing sink for raw streamed bytes. Every write is flushed so the client sees data immediately.
ThreadPool
A fixed-size pool of worker threads pulling jobs off a shared channel.

Enums§

Body
A response body: either fully buffered, or streamed incrementally.
Method
HTTP request methods sutegi recognizes.

Functions§

parse_request
Parse a single request off a buffered stream. Returns Ok(None) if the peer closed the connection before sending anything.
serve
Bind to addr and serve requests with handler until the process exits. handler is shared across worker threads, so it must be Send + Sync.
serve_until
Like serve, but stops accepting new connections once shutdown is set, then drains in-flight requests (by dropping the pool, which joins workers) and returns. This is what makes a sutegi process safe to roll in a pod: on SIGTERM you flip the flag, stop taking traffic, and let live requests finish within the termination grace period.
status_reason
Map a status code to its canonical reason phrase.
write_response
Write a response to the stream. Always closes the connection (no keep-alive) to keep the server stateless and simple. Takes the response by value so a streaming body’s FnOnce producer can be invoked.