Skip to content

Commit adbc206

Browse files
committed
Add comments
1 parent 4a4b6b8 commit adbc206

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

examples/axum.rs

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ use tokio::net::{TcpListener, TcpStream};
66
mod tls_config;
77
use tls_config::tls_acceptor;
88

9+
/// An example of running an axum server with `TlsListener`.
10+
///
11+
/// One can also bypass `axum::serve` and use the `Router` with Hyper's `serve_connection` API
12+
/// directly. The main advantages of using `axum::serve` are that
13+
/// - graceful shutdown is made easy with axum's `.with_graceful_shutdown` API, and
14+
/// - the Hyper server is configured by axum itself, allowing options specific to axum to be set
15+
/// (for example, axum currently enables the `CONNECT` protocol in order to support HTTP/2
16+
/// websockets).
917
#[tokio::main(flavor = "current_thread")]
1018
async fn main() {
1119
let app = Router::new().route("/", get(|| async { "Hello, World!" }));
@@ -31,6 +39,8 @@ impl axum::serve::Listener for Listener {
3139
type Addr = SocketAddr;
3240
async fn accept(&mut self) -> (Self::Io, Self::Addr) {
3341
loop {
42+
// To change the TLS certificate dynamically, you could `select!` on this call with a
43+
// channel receiver, and call `self.inner.replace_acceptor` in the other branch.
3444
match self.inner.accept().await {
3545
Ok(tuple) => break tuple,
3646
Err(tls_listener::Error::ListenerError(e)) if !is_connection_error(&e) => {

0 commit comments

Comments
 (0)