Skip to content

Commit 090d82d

Browse files
hawkwolix0r
authored andcommitted
http: log a warning when a CONNECT response has the wrong version (#1827)
* http: log a warning when a CONNECT response has the wrong version The issue linkerd/linkerd2#6035 describes a situation where Linkerd rejects HTTP/1.1 CONNECT requests because the remote (non-Linkerd) forward proxy returns a successful response that erroneously has the wrong HTTP version (HTTP/1.0). Since the CONNECT method does not exist in the HTTP/1.0 protocol, Linkerd does not treat this response as a CONNECT. It turns out that in the accursed Real World, some HTTP forward proxies actually do return the wrong protocol version when successfully handling CONNECT requests. We don't want to remove the check that the protocol version is correct, because it could lead to us incorrectly treating responses to CONNECTs as establishing a tunnel when they don't actually do that. However, in order to make it easier for future users who encounter issues where other proxies return wrong HTTP versions for CONNECT responses, it might be nice to log a warning, so that users can determine *why* their CONNECT requests aren't working. This branch changes the proxy to log a warning if a successful response to a CONNECT request had the wrong HTTP version. We won't log the warning if the response is not a success or if the request was not a CONNECT, so it should only cover this specific case. * format version with debug Signed-off-by: Eliza Weisman <[email protected]>
1 parent ebcf7cb commit 090d82d

File tree

1 file changed

+13
-1
lines changed
  • linkerd/proxy/http/src

1 file changed

+13
-1
lines changed

linkerd/proxy/http/src/h1.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,20 @@ pub(crate) fn wants_upgrade<B>(req: &http::Request<B>) -> bool {
241241

242242
/// Checks responses to determine if they are successful HTTP upgrades.
243243
pub(crate) fn is_upgrade<B>(res: &http::Response<B>) -> bool {
244+
#[inline]
245+
fn is_connect_success<B>(res: &http::Response<B>) -> bool {
246+
res.extensions().get::<HttpConnect>().is_some() && res.status().is_success()
247+
}
248+
244249
// Upgrades were introduced in HTTP/1.1
245250
if res.version() != http::Version::HTTP_11 {
251+
if is_connect_success(res) {
252+
tracing::warn!(
253+
"A successful response to a CONNECT request had an incorrect HTTP version \
254+
(expected HTTP/1.1, got {:?})",
255+
res.version()
256+
);
257+
}
246258
return false;
247259
}
248260

@@ -252,7 +264,7 @@ pub(crate) fn is_upgrade<B>(res: &http::Response<B>) -> bool {
252264
}
253265

254266
// CONNECT requests are complete if status code is 2xx.
255-
if res.extensions().get::<HttpConnect>().is_some() && res.status().is_success() {
267+
if is_connect_success(res) {
256268
return true;
257269
}
258270

0 commit comments

Comments
 (0)