rust_web_server/lib.rs
1//! # rust-web-server
2//!
3//! A static file web server and HTTP toolkit written in Rust.
4//! Supports HTTP/3 (QUIC), HTTP/2, and HTTP/1.1.
5//!
6//! ## Use as a library
7//!
8//! Add to `Cargo.toml`:
9//!
10//! ```toml
11//! [dependencies]
12//! rust-web-server = "17"
13//! ```
14//!
15//! ## Quick start: add a custom route
16//!
17//! ```rust,no_run
18//! use rust_web_server::controller::Controller;
19//! use rust_web_server::request::{METHOD, Request};
20//! use rust_web_server::response::{Response, STATUS_CODE_REASON_PHRASE};
21//! use rust_web_server::range::Range;
22//! use rust_web_server::mime_type::MimeType;
23//! use rust_web_server::server::ConnectionInfo;
24//!
25//! pub struct PingController;
26//!
27//! impl Controller for PingController {
28//! fn is_matching(request: &Request, _: &ConnectionInfo) -> bool {
29//! request.method == METHOD.get && request.request_uri == "/ping"
30//! }
31//!
32//! fn process(_: &Request, mut response: Response, _: &ConnectionInfo) -> Response {
33//! response.status_code = *STATUS_CODE_REASON_PHRASE.n200_ok.status_code;
34//! response.reason_phrase = STATUS_CODE_REASON_PHRASE.n200_ok.reason_phrase.to_string();
35//! response.content_range_list = vec![
36//! Range::get_content_range(b"pong".to_vec(), MimeType::TEXT_PLAIN.to_string())
37//! ];
38//! response
39//! }
40//! }
41//! ```
42//!
43//! See [DEVELOPER.md](https://github.com/bohdaq/rust-web-server/blob/main/DEVELOPER.md)
44//! for the full building blocks reference and use case examples.
45
46// Allows `::rust_web_server::…` paths to resolve from within this crate's own
47// tests, which is required by proc-macro derive output that uses that prefix.
48extern crate self as rust_web_server;
49
50pub mod app;
51#[cfg(feature = "auth")]
52pub mod auth;
53
54#[cfg(feature = "macros")]
55pub use rws_macros::{delete, get, patch, post, put, route, FromRequest, Validate};
56#[cfg(feature = "http2")]
57pub mod async_state;
58pub mod session;
59pub mod sse;
60pub mod compression;
61pub mod cookie;
62pub mod error;
63pub mod extract;
64pub mod ip_filter;
65pub mod macros;
66pub mod cache;
67pub mod config_reload;
68pub mod metrics;
69pub mod otel;
70#[cfg(feature = "acme")]
71pub mod acme;
72pub mod middleware;
73pub mod rate_limit;
74pub mod router;
75pub mod state;
76pub mod test_client;
77pub mod application;
78pub mod body;
79pub mod client_hint;
80pub mod controller;
81pub mod core;
82pub mod cors;
83pub mod entry_point;
84pub mod ext;
85pub mod header;
86pub mod http;
87pub mod json;
88pub mod language;
89pub mod log;
90pub mod mime_type;
91pub mod null;
92pub mod range;
93pub mod request;
94pub mod response;
95pub mod server;
96pub mod symbol;
97pub mod thread_pool;
98pub mod url;
99pub mod proxy;
100pub mod validate;
101pub mod websocket;
102
103#[cfg(feature = "http2")]
104#[doc(hidden)]
105pub mod tls;
106
107#[cfg(feature = "http2")]
108#[doc(hidden)]
109pub mod h2_handler;
110
111#[cfg(feature = "http3")]
112#[doc(hidden)]
113pub mod h3_handler;