From df4a36990c799901463d63c78de0f0672b675688 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 6 May 2022 12:34:19 +0200 Subject: [PATCH] Try again to fix connection: upgrade bug --- src/reverse_proxy.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/reverse_proxy.rs b/src/reverse_proxy.rs index 99a7c98..dc45869 100644 --- a/src/reverse_proxy.rs +++ b/src/reverse_proxy.rs @@ -52,8 +52,12 @@ fn copy_upgrade_headers( old_headers: &HeaderMap, new_headers: &mut HeaderMap, ) -> Result<()> { + // The Connection header is stripped as it is a hop header that we are not supposed to proxy. + // However, it might also contain an Upgrade directive, e.g. for Websockets: + // when that happen, we do want to preserve that directive. if let Some(conn) = old_headers.get(header::CONNECTION) { - if conn.to_str()?.to_lowercase() == "upgrade" { + let conn_str = conn.to_str()?.to_lowercase(); + if conn_str.split(',').map(str::trim).any(|x| x == "upgrade") { if let Some(upgrade) = old_headers.get(header::UPGRADE) { new_headers.insert(header::CONNECTION, "Upgrade".try_into()?); new_headers.insert(header::UPGRADE, upgrade.clone());