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 mcp;
61pub mod request_log;
62pub mod request_id;
63#[cfg(not(target_arch = "wasm32"))]
64pub mod otel;
65pub mod middleware;
66pub mod rate_limit;
67pub mod router;
68pub mod handler;
69pub mod schema;
70pub mod state;
71pub mod test_client;
72pub mod application;
73pub mod controller;
74pub mod language;
75#[cfg(not(target_arch = "wasm32"))]
76pub mod log;
77pub mod server;
78#[cfg(not(target_arch = "wasm32"))]
79pub mod thread_pool;
80pub mod pagination;
81pub mod rewrite;
82pub mod scheduler;
83#[cfg(not(target_arch = "wasm32"))]
84pub mod circuit_breaker;
85// `BackendPool`/`DiscoverySource` (DNS/etcd/Consul/Docker) are native-only —
86// gated internally in service_discovery/mod.rs, not at this declaration —
87// because `json_lite` (a plain JSON parser, no sockets) must stay available
88// for `secrets`'s Vault/AWS-SM/Key-Vault backends on every target.
89pub mod service_discovery;
90pub mod config_binding;
91pub mod di;
92pub mod validate;
93#[cfg(any(feature = "model-sqlite", feature = "model-postgres", feature = "model-mysql"))]
94pub mod model;
95#[cfg(not(target_arch = "wasm32"))]
96pub mod websocket;
97// Has both a native (TcpStream/rustls) and a wasm32 (wasi:http outgoing-handler)
98// backend behind Client::send() — see the #[cfg(target_arch = "wasm32")]
99// `send_once` in this module. spec/WASM_SHIM.md Phase 2 item 7.
100pub mod http_client;
101#[cfg(feature = "crypto")]
102pub mod crypto;
103#[cfg(feature = "csrf")]
104pub mod csrf;
105#[cfg(feature = "sso")]
106pub mod sso;
107#[cfg(feature = "openapi")]
108pub mod openapi;
109#[cfg(feature = "secrets")]
110pub mod secrets;
111// Runs wrapped work on a background OS thread to bound wait time — needs
112// `std::thread::spawn`, unavailable on wasm32-wasip2. See spec/WASM_SHIM.md.
113#[cfg(not(target_arch = "wasm32"))]
114pub mod timeout;
115#[cfg(feature = "http2")]
116#[doc(hidden)]
117pub mod tls;
118#[cfg(feature = "http2")]
119#[doc(hidden)]
120pub mod h2_server;
121#[cfg(feature = "http3")]
122#[doc(hidden)]
123pub mod h3_handler;
124
125// `StorageError` and the credential helpers `secrets` shares with the
126// storage backends (rust-web-server's `storage`).
127#[cfg(any(feature = "storage-local", feature = "storage-s3", feature = "storage-azure", feature = "storage-gcs", feature = "secrets"))]
128pub mod storage;
129
130/// The rustls crypto provider every TLS config uses: aws-lc-rs, or with the
131/// `fips` feature its FIPS 140-3 validated module and only the algorithms
132/// FIPS approves (18.23.0).
133#[cfg(all(any(feature = "http-client", feature = "http2"), not(target_arch = "wasm32")))]
134pub fn crypto_provider() -> rustls::crypto::CryptoProvider {
135    #[cfg(feature = "fips")]
136    return rustls::crypto::default_fips_provider();
137    #[cfg(not(feature = "fips"))]
138    rustls::crypto::aws_lc_rs::default_provider()
139}
140
141/// Whether this build uses the FIPS module (`fips` feature).
142pub const FIPS: bool = cfg!(feature = "fips");
143
144/// A rustls client-config builder with this crate's crypto provider
145/// (aws-lc-rs) named explicitly. `rustls::ClientConfig::builder()` uses the
146/// process-wide default provider and panics when none is installed and more
147/// than one is compiled in — which happens as soon as any dependency enables
148/// rustls's `ring` backend (e.g. sqlx). Every outbound TLS client in the
149/// crate starts here.
150#[cfg(all(any(feature = "http-client", feature = "http2"), not(target_arch = "wasm32")))]
151#[doc(hidden)]
152pub fn tls_client_builder() -> rustls::ConfigBuilder<rustls::ClientConfig, rustls::WantsVerifier> {
153    rustls::ClientConfig::builder_with_provider(std::sync::Arc::new(crate::crypto_provider()))
154        .with_safe_default_protocol_versions()
155        .expect("aws-lc-rs supports rustls's default protocol versions")
156}
157
158
159#[cfg(test)]
160pub(crate) mod test_env;
161
162// Derives (rws-macros) for this crate's tests and doctests; their output
163// names `rust_web_server::…`, which is this crate there (`extern crate self`
164// above, `extern crate rws_server as rust_web_server` in doctests).
165#[cfg(feature = "macros")]
166#[doc(hidden)]
167pub use rws_macros::{Config, FromPath, FromRequest, JsonSchema, Validate};