Expand description
An HTTP/1, HTTP/2 and HTTP/3 library.
Soyokaze speaks all three versions of HTTP through one set of types. A
Message carries a request or a response regardless of the version that
framed it, and every connection implements protocol::base::Connection,
so code written against the trait works unchanged over HTTP/1.1, HTTP/2 and
HTTP/3.
§Layers
The crate is arranged in layers, each usable on its own, and each module standing alone as a library for exactly its own concern:
helpersholds the codecs the versions share —helpers::huffman,helpers::hpackfor HTTP/2 andhelpers::qpackfor HTTP/3, over the shared vocabulary inhelpers::fields— plus the small pieces (helpers::base64,helpers::sha1,helpers::text,helpers::scan,helpers::sync) everything else leans on. Nothing here knows about connections or transports.modelsis the vocabulary:Message,Headers,Version,Port,Limits.tlsholds the TLS side of it —Securityand the BoringSSL contexts — andcookies,hsts,responsesandfinalizereach hold one message-level concern.protocolholds one connection type per version —protocol::h1,protocol::h2andprotocol::h3— implementing the traits inprotocol::baseover the shared vocabulary inprotocol::common. Each binary version keeps its wire format in a module of its own (protocol::h2::frames,protocol::h3::frames), which encodes and decodes frames and knows nothing of connections, exactly ashelpers::hpackandhelpers::qpackdo for field compression.protocol::quicis the seam QUIC is consumed through, the transport counterpart ofprotocol::base::Transport, andprotocol::handlerbridges each transport into a connection the same way. A higher layer drives a lower one exactly the way an outside caller would.apiholds the entry points:Clientdials an origin,Serverbinds ports and accepts connections,api::gateadmits them, andapi::clusterruns the server across worker threads.
§Symmetry
Corresponding pieces are kept interchangeable on purpose. Client and server,
request and response, encoder and decoder, HTTP/1 and HTTP/2 and HTTP/3 —
each pair shares the shape of its counterpart, and version-specific
connections are drop-in replacements for one another wherever the protocol
itself does not force a difference. Prefer naming the base type
(protocol::base::Connection, AnyConnection) over a concrete
version wherever a choice exists. Nothing keys on a version where the
transport is the real question: a port carries whichever versions run over
its transport, per Port::carries, so a new version slots in without
touching the routing.
§Getting started
Fetch a resource:
let client = soyokaze::Client::default();
let response = client.get("https://example.com/").await?;
println!("{:?}", response.status_code);Serve one:
use soyokaze::{Port, Server};
struct Echo;
impl soyokaze::Handler for Echo {}
let server = Server::default();
let handle = server.serve(Echo, &[Port::TCP(8080)]).await?;
handle.close(None).await;Re-exports§
pub use errors::Error;pub use models::ALPN;pub use models::Body;pub use models::ConnectionID;pub use models::HeaderCase;pub use models::Headers;pub use models::Limits;pub use models::Message;pub use models::Method;pub use models::Port;pub use models::Role;pub use models::StreamID;pub use models::TransportKind;pub use models::URL;pub use models::Version;pub use cookies::Cookie;pub use cookies::CookieJar;pub use cookies::CookieLimits;pub use cookies::SameSite;pub use cookies::SetCookie;pub use finalizer::DateCache;pub use finalizer::RequestFinalizer;pub use finalizer::ResponseFinalizer;pub use api::common::VERSIONS;pub use api::client::Client;pub use api::client::ClientConfig;pub use api::client::ClientLimits;pub use api::server::Handler;pub use api::server::RawSocket;pub use api::server::Server;pub use api::server::ServerConfig;pub use api::server::ServerLimits;pub use api::gate::Gate;pub use api::gate::Permit;pub use api::cluster::Cluster;pub use tls::ECHConfig;pub use tls::ECHConfigList;pub use tls::ECHKeys;pub use tls::ECHStatus;pub use tls::Format;pub use tls::Identity;pub use tls::Security;pub use tls::TLSCipher;pub use tls::TLSGroup;pub use tls::TLSVersion;pub use hsts::HSTSLimits;pub use hsts::HSTSPolicy;pub use hsts::HSTSStore;pub use helpers::compression::Compression;pub use helpers::text::Text;pub use websocket::WebSocketConnection;pub use websocket::WebSocketLimits;
Modules§
- api
- The entry points a user of the crate reaches for first.
- cookies
- Cookies.
- errors
- The error every fallible operation in the crate reports.
- ffi
- A C ABI over the crate, for callers outside Rust.
- finalizer
- The fields an endpoint fills in for itself just before a message goes out.
- helpers
- The codecs and utilities the protocol implementations share.
- hsts
- HTTP Strict Transport Security.
- models
- The types every HTTP version shares.
- protocol
- One connection type per HTTP version, over a shared vocabulary.
- responses
- Constructors for the responses a handler reaches for most.
- tls
- TLS contexts, identities and Encrypted Client Hello.
- websocket
- The WebSocket protocol, over all three versions of HTTP.