hyper_server/lib.rs
1//! hyper-server is a [hyper] server implementation designed to be used with [axum] framework.
2//!
3//! # Features
4//!
5//! - HTTP/1 and HTTP/2
6//! - HTTPS through [rustls] or [openssl].
7//! - High performance through [hyper].
8//! - Using [tower] make service API.
9//! - Very good [axum] compatibility. Likely to work with future [axum] releases.
10//! - Proxy protocol support for use behind network load balancers.
11//!
12//! # Guide
13//!
14//! hyper-server can [`serve`] items that implement [`MakeService`] with some additional [trait
15//! bounds](crate::service::MakeServiceRef). Make services that are [created] using [`axum`]
16//! complies with those trait bounds out of the box. Therefore it is more convenient to use this
17//! crate with [`axum`].
18//!
19//! All examples in this crate uses [`axum`]. If you want to use this crate without [`axum`] it is
20//! highly recommended to learn how [tower] works.
21//!
22//! [`Server::bind`] or [`bind`] function can be called to create a server that will bind to
23//! provided [`SocketAddr`] when [`serve`] is called.
24//!
25//! A [`Handle`] can be passed to [`Server`](Server::handle) for additional utilities like shutdown
26//! and graceful shutdown.
27//!
28//! [`bind_rustls`] can be called by providing [`RustlsConfig`] to create a HTTPS [`Server`] that
29//! will bind on provided [`SocketAddr`]. [`RustlsConfig`] can be cloned, reload methods can be
30//! used on clone to reload tls configuration.
31//!
32//! # Features
33//!
34//! * `tls-rustls` - activate [rustls] support.
35//! * `tls-openssl` - activate [openssl] support.
36//!
37//! # Example
38//!
39//! A simple hello world application can be served like:
40//!
41//! ```rust,no_run
42//! use axum::{routing::get, Router};
43//! use std::net::SocketAddr;
44//!
45//! #[tokio::main]
46//! async fn main() {
47//! let app = Router::new().route("/", get(|| async { "Hello, world!" }));
48//!
49//! let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
50//! println!("listening on {}", addr);
51//! hyper_server::bind(addr)
52//! .serve(app.into_make_service())
53//! .await
54//! .unwrap();
55//! }
56//! ```
57//!
58//! You can find more examples in [repository].
59//!
60//! [axum]: https://crates.io/crates/axum
61//! [bind]: crate::bind
62//! [bind_rustls]: crate::bind_rustls
63//! [created]: https://docs.rs/axum/0.3/axum/struct.Router.html#method.into_make_service
64//! [hyper]: https://crates.io/crates/hyper
65//! [openssl]: https://crates.io/crates/openssl
66//! [repository]: https://github.com/valorem-labs-inc/hyper-server/examples
67//! [rustls]: https://crates.io/crates/rustls
68//! [tower]: https://crates.io/crates/tower
69//! [`axum`]: https://docs.rs/axum/0.3
70//! [`serve`]: crate::server::Server::serve
71//! [`MakeService`]: https://docs.rs/tower/0.4/tower/make/trait.MakeService.html
72//! [`RustlsConfig`]: crate::tls_rustls::RustlsConfig
73//! [`SocketAddr`]: std::net::SocketAddr
74
75#![forbid(unsafe_code)]
76#![warn(
77 clippy::await_holding_lock,
78 clippy::cargo_common_metadata,
79 clippy::dbg_macro,
80 clippy::doc_markdown,
81 clippy::empty_enum,
82 clippy::enum_glob_use,
83 clippy::inefficient_to_string,
84 clippy::mem_forget,
85 clippy::mutex_integer,
86 clippy::needless_continue,
87 clippy::todo,
88 clippy::unimplemented,
89 clippy::wildcard_imports,
90 future_incompatible,
91 missing_docs,
92 missing_debug_implementations,
93 unreachable_pub
94)]
95#![cfg_attr(docsrs, feature(doc_cfg))]
96
97mod addr_incoming_config;
98mod handle;
99mod http_config;
100mod notify_once;
101mod server;
102
103pub mod accept;
104pub mod service;
105
106pub use self::{
107 addr_incoming_config::AddrIncomingConfig,
108 handle::Handle,
109 http_config::HttpConfig,
110 server::{bind, from_tcp, Server},
111};
112
113#[cfg(feature = "tls-rustls")]
114#[cfg_attr(docsrs, doc(cfg(feature = "tls-rustls")))]
115pub mod tls_rustls;
116
117#[doc(inline)]
118#[cfg(feature = "tls-rustls")]
119pub use self::tls_rustls::export::{bind_rustls, from_tcp_rustls};
120
121#[cfg(feature = "tls-openssl")]
122#[cfg_attr(docsrs, doc(cfg(feature = "tls-openssl")))]
123pub mod tls_openssl;
124
125#[doc(inline)]
126#[cfg(feature = "tls-openssl")]
127pub use self::tls_openssl::bind_openssl;
128
129#[cfg(feature = "proxy-protocol")]
130#[cfg_attr(docsrs, doc(cfg(feature = "proxy_protocol")))]
131pub mod proxy_protocol;