Skip to main content

rws_server/
lib.rs

1//! The server layer of [rust-web-server](https://crates.io/crates/rust-web-server):
2//! the HTTP/1.1, HTTP/2 and HTTP/3 servers, TLS, the `App` and its
3//! controllers, routing, state-aware apps, middleware, MCP, OpenAPI, SSO,
4//! sessions, metrics, OpenTelemetry, the HTTP client and the model layer.
5//!
6//! Internal to rust-web-server, released with it at the same version: use
7//! these through the `rust_web_server` paths, which stay stable; this
8//! crate's own layout may change in any release. See
9//! `spec/WORKSPACE_SPLIT.md`.
10
11// Derive output (rws-macros) names `::rust_web_server::…`; in this crate's
12// tests that is this crate.
13#[cfg(test)]
14extern crate self as rust_web_server;
15
16// The layers below, under the paths the moved code uses (`crate::request`, …);
17// public (hidden) so doctests can name them as `rust_web_server::…`.
18#[allow(unused_imports)]
19#[doc(hidden)]
20pub use rws_base::{core, dns, ext, http, mime_type, null, symbol, url};
21// Not every module is used in every feature set.
22#[allow(unused_imports)]
23#[doc(hidden)]
24pub use rws_http::{body, client_hint, compression, cors, entry_point, error, extract, header, json, range, request, response, server_config, virtual_host};
25
26pub mod app;
27#[cfg(feature = "auth")]
28pub mod auth;
29#[cfg(feature = "http2")]
30pub mod async_state;
31#[cfg(feature = "http2")]
32#[doc(hidden)]
33pub mod async_bridge;
34pub mod session;
35// Socket-coupled — see spec/WASM_SHIM.md for what a wasm32-wasip2 build
36// excludes and why (no OS threads, no raw TCP/TLS in a WASI guest).
37#[cfg(not(target_arch = "wasm32"))]
38#[doc(hidden)]
39pub mod redis_protocol;
40pub mod sse;
41pub mod cookie;
42#[cfg(all(unix, any(feature = "http1", feature = "http2")))]
43pub mod systemd;
44pub mod ip_filter;
45pub mod blocklist;
46pub mod cache;
47pub mod early_hints;
48pub mod disk_guard;
49pub mod authz;
50pub mod config_reload;
51#[cfg(not(target_arch = "wasm32"))]
52pub mod config_watch;
53/// RSA public keys and RS256 / rsa-sha256 signature verification (no `rsa` crate).
54#[cfg(any(feature = "auth-asymmetric", feature = "sso"))]
55pub mod rsa_key;
56pub mod feature;
57pub mod maintenance;
58pub mod metrics;
59pub mod mcp;
60pub mod request_log;
61pub mod request_id;
62#[cfg(not(target_arch = "wasm32"))]
63pub mod otel;
64pub mod middleware;
65pub mod rate_limit;
66pub mod router;
67pub mod schema;
68pub mod state;
69pub mod test_client;
70pub mod application;
71pub mod controller;
72pub mod language;
73#[cfg(not(target_arch = "wasm32"))]
74pub mod log;
75pub mod server;
76#[cfg(not(target_arch = "wasm32"))]
77pub mod thread_pool;
78pub mod pagination;
79pub mod rewrite;
80pub mod scheduler;
81#[cfg(not(target_arch = "wasm32"))]
82pub mod circuit_breaker;
83// `BackendPool`/`DiscoverySource` (DNS/etcd/Consul/Docker) are native-only —
84// gated internally in service_discovery/mod.rs, not at this declaration —
85// because `json_lite` (a plain JSON parser, no sockets) must stay available
86// for `secrets`'s Vault/AWS-SM/Key-Vault backends on every target.
87pub mod service_discovery;
88pub mod config_binding;
89pub mod di;
90pub mod validate;
91#[cfg(any(feature = "model-sqlite", feature = "model-postgres", feature = "model-mysql"))]
92pub mod model;
93#[cfg(not(target_arch = "wasm32"))]
94pub mod websocket;
95// Has both a native (TcpStream/rustls) and a wasm32 (wasi:http outgoing-handler)
96// backend behind Client::send() — see the #[cfg(target_arch = "wasm32")]
97// `send_once` in this module. spec/WASM_SHIM.md Phase 2 item 7.
98pub mod http_client;
99#[cfg(feature = "crypto")]
100pub mod crypto;
101#[cfg(feature = "csrf")]
102pub mod csrf;
103#[cfg(feature = "sso")]
104pub mod sso;
105#[cfg(feature = "openapi")]
106pub mod openapi;
107#[cfg(feature = "secrets")]
108pub mod secrets;
109// Runs wrapped work on a background OS thread to bound wait time — needs
110// `std::thread::spawn`, unavailable on wasm32-wasip2. See spec/WASM_SHIM.md.
111#[cfg(not(target_arch = "wasm32"))]
112pub mod timeout;
113#[cfg(feature = "http2")]
114#[doc(hidden)]
115pub mod tls;
116#[cfg(feature = "http2")]
117#[doc(hidden)]
118pub mod h2_server;
119#[cfg(feature = "http3")]
120#[doc(hidden)]
121pub mod h3_handler;
122
123// `StorageError` and the credential helpers `secrets` shares with the
124// storage backends (rust-web-server's `storage`).
125#[cfg(any(feature = "storage-local", feature = "storage-s3", feature = "storage-azure", feature = "storage-gcs", feature = "secrets"))]
126pub mod storage;
127
128/// The rustls crypto provider every TLS config uses: aws-lc-rs, or with the
129/// `fips` feature its FIPS 140-3 validated module and only the algorithms
130/// FIPS approves (18.23.0).
131#[cfg(all(any(feature = "http-client", feature = "http2"), not(target_arch = "wasm32")))]
132pub fn crypto_provider() -> rustls::crypto::CryptoProvider {
133    #[cfg(feature = "fips")]
134    return rustls::crypto::default_fips_provider();
135    #[cfg(not(feature = "fips"))]
136    rustls::crypto::aws_lc_rs::default_provider()
137}
138
139/// Whether this build uses the FIPS module (`fips` feature).
140pub const FIPS: bool = cfg!(feature = "fips");
141
142/// A rustls client-config builder with this crate's crypto provider
143/// (aws-lc-rs) named explicitly. `rustls::ClientConfig::builder()` uses the
144/// process-wide default provider and panics when none is installed and more
145/// than one is compiled in — which happens as soon as any dependency enables
146/// rustls's `ring` backend (e.g. sqlx). Every outbound TLS client in the
147/// crate starts here.
148#[cfg(all(any(feature = "http-client", feature = "http2"), not(target_arch = "wasm32")))]
149#[doc(hidden)]
150pub fn tls_client_builder() -> rustls::ConfigBuilder<rustls::ClientConfig, rustls::WantsVerifier> {
151    rustls::ClientConfig::builder_with_provider(std::sync::Arc::new(crate::crypto_provider()))
152        .with_safe_default_protocol_versions()
153        .expect("aws-lc-rs supports rustls's default protocol versions")
154}
155
156
157#[cfg(test)]
158pub(crate) mod test_env;
159
160// Derives (rws-macros) for this crate's tests and doctests; their output
161// names `rust_web_server::…`, which is this crate there (`extern crate self`
162// above, `extern crate rws_server as rust_web_server` in doctests).
163#[cfg(feature = "macros")]
164#[doc(hidden)]
165pub use rws_macros::{Config, FromRequest, JsonSchema, Validate};