diff --git a/linkerd/http/upgrade/src/upgrade.rs b/linkerd/http/upgrade/src/upgrade.rs index 14bbc6ffa1..5540266981 100644 --- a/linkerd/http/upgrade/src/upgrade.rs +++ b/linkerd/http/upgrade/src/upgrade.rs @@ -37,11 +37,6 @@ struct Http11UpgradeHalves { client: Http11Upgrade, } -/// A marker type inserted into Extensions to signal it was an HTTP CONNECT -/// request. -#[derive(Debug)] -pub struct HttpConnect; - struct Inner { server: TryLock>, client: TryLock>, diff --git a/linkerd/proxy/http/src/h1.rs b/linkerd/proxy/http/src/h1.rs index b43dd1874a..b91a23a24a 100644 --- a/linkerd/proxy/http/src/h1.rs +++ b/linkerd/proxy/http/src/h1.rs @@ -6,10 +6,7 @@ use http::{ }; use linkerd_error::{Error, Result}; use linkerd_http_box::BoxBody; -use linkerd_http_upgrade::{ - glue::HyperConnect, - upgrade::{Http11Upgrade, HttpConnect}, -}; +use linkerd_http_upgrade::{glue::HyperConnect, upgrade::Http11Upgrade}; use linkerd_stack::MakeConnection; use std::{pin::Pin, time::Duration}; use tracing::{debug, trace}; @@ -139,12 +136,6 @@ where Box::pin(async move { let mut rsp = rsp_fut.await?; if is_http_connect { - // Add an extension to indicate that this a response to a CONNECT request. - debug_assert!( - upgrade.is_some(), - "Upgrade extension must be set on CONNECT requests" - ); - rsp.extensions_mut().insert(HttpConnect); // Strip headers that may not be transmitted to the server, per RFC 9110: // // > A server MUST NOT send any `Transfer-Encoding` or `Content-Length` header @@ -159,7 +150,7 @@ where } } - if is_upgrade(&rsp) { + if is_upgrade(&rsp, is_http_connect) { trace!("Client response is HTTP/1.1 upgrade"); if let Some(upgrade) = upgrade { upgrade.insert_half(hyper::upgrade::on(&mut rsp))?; @@ -174,36 +165,32 @@ where } /// Checks responses to determine if they are successful HTTP upgrades. -fn is_upgrade(res: &http::Response) -> bool { - #[inline] - fn is_connect_success(res: &http::Response) -> bool { - res.extensions().get::().is_some() && res.status().is_success() - } - - // Upgrades were introduced in HTTP/1.1 - if res.version() != http::Version::HTTP_11 { - if is_connect_success(res) { - tracing::warn!( - "A successful response to a CONNECT request had an incorrect HTTP version \ - (expected HTTP/1.1, got {:?})", - res.version() - ); +fn is_upgrade(rsp: &http::Response, is_http_connect: bool) -> bool { + use http::Version; + + match rsp.version() { + Version::HTTP_11 => match rsp.status() { + // `101 Switching Protocols` indicates an upgrade. + http::StatusCode::SWITCHING_PROTOCOLS => true, + // CONNECT requests are complete if status code is 2xx. + status if is_http_connect && status.is_success() => true, + // Just a regular HTTP response... + _ => false, + }, + version => { + // Upgrades are specific to HTTP/1.1. They are not included in HTTP/1.0, nor are they + // supported in HTTP/2. If this response is associated with any protocol version + // besides HTTP/1.1, it is not applicable to an upgrade. + if is_http_connect && rsp.status().is_success() { + tracing::warn!( + "A successful response to a CONNECT request had an incorrect HTTP version \ + (expected HTTP/1.1, got {:?})", + version + ); + } + false } - return false; } - - // 101 Switching Protocols - if res.status() == http::StatusCode::SWITCHING_PROTOCOLS { - return true; - } - - // CONNECT requests are complete if status code is 2xx. - if is_connect_success(res) { - return true; - } - - // Just a regular HTTP response... - false } /// Returns if the request target is in `absolute-form`.