v0.32.4
This commit is contained in:
1 parent
b0f211555a
commit
8b9ca4db44
39 files changed
+1481
-303
No files matched your search
+44
-1
@@ -158,6 +158,46 @@ fn legacy_websocket_origin(
|
||||
HeaderValue::from_str(&format!("{scheme}://{authority}")).ok()
|
||||
}
|
||||
|
||||
/// Align HTTP request authority with the selected public/backend Host.
|
||||
///
|
||||
/// TCP/DNS/TLS still target the configured origin in TimedConnector. Strict
|
||||
/// HTTP/2 sends :authority without a second Host field. HTTPS ALPN mixed
|
||||
/// mode must retain the Host field: Hyper's legacy H1-compatible request may
|
||||
/// be sent over an H2-negotiated connection, and H1 fallback needs Host.
|
||||
fn upstream_request_target(
|
||||
uri: &Uri,
|
||||
headers: &mut HeaderMap,
|
||||
backend: &crate::config::CompiledBackend,
|
||||
websocket_h1: bool,
|
||||
websocket_h2: bool,
|
||||
) -> Option<Uri> {
|
||||
let h2_capable = !websocket_h1 && match backend.protocol {
|
||||
crate::config::UpstreamProtocol::Http1 => false,
|
||||
crate::config::UpstreamProtocol::Auto => backend.origin.starts_with("https://"),
|
||||
crate::config::UpstreamProtocol::Http2 | crate::config::UpstreamProtocol::H2 => true,
|
||||
};
|
||||
if !h2_capable {
|
||||
return Some(uri.clone());
|
||||
}
|
||||
let selected = headers.get(HOST).unwrap_or(&backend.host_header);
|
||||
let authority: http::uri::Authority = selected.to_str().ok()?.parse().ok()?;
|
||||
// Never treat a userinfo URI or a malformed Host as a valid HTTP authority.
|
||||
if authority.host().is_empty() || authority.as_str().contains('@') {
|
||||
return None;
|
||||
}
|
||||
let mut parts = uri.clone().into_parts();
|
||||
parts.authority = Some(authority);
|
||||
let target = Uri::from_parts(parts).ok()?;
|
||||
let strict_h2_request = websocket_h2
|
||||
|| backend.protocol == crate::config::UpstreamProtocol::H2
|
||||
|| (backend.protocol == crate::config::UpstreamProtocol::Http2
|
||||
&& backend.origin.starts_with("http://"));
|
||||
if strict_h2_request {
|
||||
headers.remove(HOST);
|
||||
}
|
||||
Some(target)
|
||||
}
|
||||
|
||||
fn upstream_request_version(
|
||||
backend: &crate::config::CompiledBackend,
|
||||
websocket_h2: bool,
|
||||
@@ -188,7 +228,8 @@ fn retry_request(
|
||||
let mut request = Request::builder()
|
||||
.method(method.clone())
|
||||
.version(version)
|
||||
.uri(uri)
|
||||
// Keep the original URI for authority adjustment after building the request.
|
||||
.uri(uri.clone())
|
||||
.body(Body::empty())
|
||||
.ok()?;
|
||||
*request.headers_mut() = headers.clone();
|
||||
@@ -202,6 +243,8 @@ fn retry_request(
|
||||
},
|
||||
);
|
||||
}
|
||||
let target = upstream_request_target(&uri, request.headers_mut(), backend, false, false)?;
|
||||
*request.uri_mut() = target;
|
||||
Some(request)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user