Skip to content

Commit a74630c

Browse files
madeyeclaude
andcommitted
Add HTTP/2 support via auto protocol detection
Use hyper-util auto builder to handle both HTTP/1.1 and HTTP/2 connections. CONNECT upgrades remain available on HTTP/1.1. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4cb8ddb commit a74630c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ futures = "0.3"
1414
base64 = "0.22"
1515
clap = { version = "4", features = ["derive"] }
1616
http-body-util = "0.1"
17-
hyper = { version = "1", features = ["http1", "server", "client"] }
18-
hyper-util = { version = "0.1", features = ["tokio", "http1", "server-auto", "client-legacy"] }
17+
hyper = { version = "1", features = ["http1", "http2", "server", "client"] }
18+
hyper-util = { version = "0.1", features = ["tokio", "http1", "http2", "server-auto", "client-legacy"] }
1919
libc = "0.2"
2020
serde = { version = "1", features = ["derive"] }
2121
socket2 = { version = "0.5", features = ["all"] }

src/main.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,16 @@ async fn run_server(config_path: String) -> anyhow::Result<()> {
130130
async move { handle_request(req, &shared).await }
131131
});
132132

133-
if let Err(e) = hyper::server::conn::http1::Builder::new()
134-
.preserve_header_case(true)
135-
.title_case_headers(true)
136-
.serve_connection(io, service)
137-
.with_upgrades()
138-
.await
133+
if let Err(e) = hyper_util::server::conn::auto::Builder::new(
134+
hyper_util::rt::TokioExecutor::new(),
135+
)
136+
.http1()
137+
.preserve_header_case(true)
138+
.title_case_headers(true)
139+
.http2()
140+
.max_concurrent_streams(250)
141+
.serve_connection_with_upgrades(io, service)
142+
.await
139143
{
140144
error!("{peer_addr}: connection error: {e}");
141145
}

0 commit comments

Comments
 (0)