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