A file-based way to set tuning knobs without recompiling. urus is a library, so it never presumes a config path or reads the environment — the binary hands the text in: - Config::with_toml_str(&str) -> Result<Config, ConfigError>: sparse overlay onto an existing Config (built with the addr the binary chose). Only keys present are applied; durations are integer seconds; unknown keys are a hard error (deny_unknown_fields) so a typo is loud, not a silent no-op. - Scope: the four slowloris knobs (head_timeout_secs, body_timeout_secs, body_burst_bytes, body_stall_timeout_secs). Migrating the rest of Config into the file is a separate, additive job — TomlOverrides just grows. - Feature `config-file = ["dep:serde", "dep:toml"]`; the optional serde dep gains the derive feature. The default build is unchanged (deps + code are all gated). - examples/serve_toml.rs (required-features = ["config-file"]): a `--config PATH` demo with no presumed default location. plain_serve and its env vars are left untouched. Tests (feature-gated): empty keeps defaults, partial overrides only named, full overrides all, unknown key errors, malformed errors. 84 lib with the feature / 79 without; clippy --lib clean both ways; e2e smoke serves 200 from a file and rejects an unknown key loudly.
49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
//! # urus — a cowboy/bandit-style HTTP library for the smarm actor runtime.
|
|
//!
|
|
//! v1 covers HTTP/1.1, the plug pipeline, and a built-in router. See
|
|
//! `urus-spec.md` for the design.
|
|
//!
|
|
//! ```no_run
|
|
//! use urus::{Pipeline, Router, Conn, Next, serve};
|
|
//!
|
|
//! let pipeline = Pipeline::new().plug(
|
|
//! Router::new()
|
|
//! .get("/", |c: Conn, _n: Next| c.put_status(200).put_body("hello"))
|
|
//! .get("/users/:id", |c: Conn, _n: Next| {
|
|
//! let id = c.params.get("id").unwrap_or("").to_string();
|
|
//! c.put_status(200).put_body(id)
|
|
//! })
|
|
//! );
|
|
//!
|
|
//! serve("0.0.0.0:8080", pipeline).unwrap();
|
|
//! ```
|
|
|
|
pub mod conn;
|
|
pub mod plug;
|
|
pub mod router;
|
|
pub mod parser;
|
|
pub mod net;
|
|
pub mod conn_actor;
|
|
pub mod conn_registry;
|
|
pub mod serve;
|
|
pub mod sse;
|
|
pub mod ws;
|
|
pub mod pubsub;
|
|
#[cfg(feature = "channels")]
|
|
pub mod channels;
|
|
|
|
// Re-exports — what most users want at the crate root.
|
|
pub use conn::{Assigns, Body, Conn, HeaderMap, HttpVersion, Method, Params, RespBody, StreamBody};
|
|
pub use plug::{Next, Pipeline, Plug};
|
|
pub use router::Router;
|
|
pub use sse::{EventSender, SseClosed};
|
|
pub use pubsub::{PubSub, PubSubDown};
|
|
#[cfg(feature = "channels")]
|
|
pub use channels::{Channel, ChannelHub, ChannelSession, ChannelSocket, PrefixRouter, Status, TopicRouter};
|
|
pub use ws::{Message, WsClosed, WsHandler, WsSender};
|
|
pub use serve::{
|
|
serve, serve_with, serve_with_shutdown, shutdown_handle, Config, Handle, ShutdownSignal,
|
|
};
|
|
#[cfg(feature = "config-file")]
|
|
pub use serve::ConfigError;
|