Skip to content

Commit 86410ad

Browse files
authored
Merge pull request #91 from fluffysquirrels/alpn-example-server
Server example: Configure ALPN to accept h2, http/1.1
2 parents f72ae09 + 214ffe1 commit 86410ad

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

examples/server.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use hyper::{Body, Method, Request, Response, Server, StatusCode};
1313
use rustls::internal::pemfile;
1414
use std::pin::Pin;
1515
use std::{env, fs, io, sync};
16+
use std::vec::Vec;
1617
use tokio::net::tcp::{TcpListener, TcpStream};
1718
use tokio_rustls::server::TlsStream;
1819
use tokio_rustls::TlsAcceptor;
@@ -49,6 +50,11 @@ async fn run_server() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
4950
// Select a certificate to use.
5051
cfg.set_single_cert(certs, key)
5152
.map_err(|e| error(format!("{}", e)))?;
53+
// Configure ALPN to accept HTTP/2, HTTP/1.1 in that order.
54+
cfg.set_protocols(&[
55+
b"h2".to_vec(),
56+
b"http/1.1".to_vec(),
57+
]);
5258
sync::Arc::new(cfg)
5359
};
5460

0 commit comments

Comments
 (0)