Commit adbc206 1 parent 4a4b6b8 commit adbc206 Copy full SHA for adbc206
File tree 1 file changed +10
-0
lines changed
1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,14 @@ use tokio::net::{TcpListener, TcpStream};
6
6
mod tls_config;
7
7
use tls_config:: tls_acceptor;
8
8
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).
9
17
#[ tokio:: main( flavor = "current_thread" ) ]
10
18
async fn main ( ) {
11
19
let app = Router :: new ( ) . route ( "/" , get ( || async { "Hello, World!" } ) ) ;
@@ -31,6 +39,8 @@ impl axum::serve::Listener for Listener {
31
39
type Addr = SocketAddr ;
32
40
async fn accept ( & mut self ) -> ( Self :: Io , Self :: Addr ) {
33
41
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.
34
44
match self . inner . accept ( ) . await {
35
45
Ok ( tuple) => break tuple,
36
46
Err ( tls_listener:: Error :: ListenerError ( e) ) if !is_connection_error ( & e) => {
You can’t perform that action at this time.
0 commit comments