From 8affec05ab972d8f3777989ed62b9b744de0d2a0 Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Sun, 15 Feb 2026 17:36:38 +0800 Subject: [PATCH] fix: non-utf8 char may cause panic when calling to_str --- src/proto/h2/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/proto/h2/mod.rs b/src/proto/h2/mod.rs index e6f40f3467..1a70b789c7 100644 --- a/src/proto/h2/mod.rs +++ b/src/proto/h2/mod.rs @@ -64,17 +64,17 @@ fn strip_connection_headers(headers: &mut HeaderMap, is_request: bool) { "Connection header illegal in HTTP/2: {}", CONNECTION.as_str() ); - let header_contents = header.to_str().unwrap(); - // A `Connection` header may have a comma-separated list of names of other headers that // are meant for only this specific connection. // // Iterate these names and remove them as headers. Connection-specific headers are // forbidden in HTTP2, as that information has been moved into frame types of the h2 // protocol. - for name in header_contents.split(',') { - let name = name.trim(); - headers.remove(name); + if let Ok(header_contents) = header.to_str() { + for name in header_contents.split(',') { + let name = name.trim(); + headers.remove(name); + } } } }