Try again to fix connection: upgrade bug

This commit is contained in:
Alex 2022-05-06 12:34:19 +02:00
parent 8c6114c3d3
commit df4a36990c
Signed by: lx
GPG Key ID: 0E496D15096376BE
1 changed files with 5 additions and 1 deletions

View File

@ -52,8 +52,12 @@ fn copy_upgrade_headers(
old_headers: &HeaderMap<HeaderValue>,
new_headers: &mut HeaderMap<HeaderValue>,
) -> 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());