8000 refactor(http/upgrade): remove `HttpConnect` extension by cratelyn · Pull Request #3779 · linkerd/linkerd2-proxy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor(http/upgrade): remove HttpConnect extension #3779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions linkerd/http/upgrade/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<OnUpgrade>>,
client: TryLock<Option<OnUpgrade>>,
Expand Down
65 changes: 26 additions & 39 deletions linkerd/proxy/http/src/h1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand All @@ -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))?;
Expand All @@ -174,36 +165,32 @@ where
}

/// Checks responses to determine if they are successful HTTP upgrades.
fn is_upgrade<B>(res: &http::Response<B>) -> bool {
#[inline]
fn is_connect_success<B>(res: &http::Response<B>) -> bool {
res.extensions().get::<HttpConnect>().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<B>(rsp: &http::Response<B>, 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`.
Expand Down
Loading
0