1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! # httpsd
//!
//! A pure-Rust HTTP/1.x server with a **sans-I/O core** and **pluggable
//! runtimes**. The protocol engine ([`proto::H1Conn`]) performs no I/O at all —
//! it turns bytes into [`Request`]s and serializes [`Response`]s back into
//! bytes. Runtimes in [`rt`] move those bytes over real sockets; TLS (via
//! [`purecrypto`](https://docs.rs/purecrypto)) and response compression (via
//! [`compcol`](https://docs.rs/compcol)) are independent layers you can enable
//! with Cargo features.
//!
//! ## As a library
//!
//! ```no_run
//! use httpsd::{Server, Response};
//!
//! # #[cfg(feature = "rt-threadpool")]
//! # fn main() -> httpsd::Result<()> {
//! let server = Server::bind("127.0.0.1:8080")?
//! .handler(|req: &httpsd::Request| Response::text(format!("you asked for {}", req.path())));
//! server.run()?;
//! # Ok(())
//! # }
//! # #[cfg(not(feature = "rt-threadpool"))]
//! # fn main() {}
//! ```
//!
//! ## Feature flags
//!
//! - `tls` — HTTPS via `purecrypto`'s sans-I/O TLS engine.
//! - `compress` — gzip/deflate/zlib response compression via `compcol`.
//! - `router` — a [`Router`] with method/path matching plus the
//! [`IntoResponse`] trait (dependency-free).
//! - `http` — `From`/`TryFrom` interop with the [`http`](https://docs.rs/http)
//! crate's `Request`/`Response`/`Method`/`StatusCode`/`Headers` types.
//! - `config` — load a [`ServerConfig`] from a TOML file.
//! - `cli` — build the `httpsd` binary.
//! - `rt-threadpool` (default), `rt-tokio`, `rt-mio` — runtime drivers.
// The crate is unsafe-free except for the optional `privdrop` module, whose
// privilege-dropping syscalls (setuid/setgid/chroot via libc) require `unsafe`.
// When that feature is off we keep the hard `forbid`; when it is on we downgrade
// to `deny` so the single module can opt back in with a scoped `allow`.
pub use ;
pub use Handler;
pub use ;
pub use Session;
pub use StaticFiles;
pub use ;
pub use ServerConfig;
pub use Server;