fix(rustproxy-http): use the requested domain as HTTP/2 authority instead of the backend host and port

This commit is contained in:
2026-03-12 22:06:11 +00:00
parent de3b8d3f58
commit b3dc0a6db2
3 changed files with 19 additions and 13 deletions

View File

@@ -1084,9 +1084,9 @@ impl HttpProxyService {
});
// Build request with empty body using absolute URI for H2 pseudo-headers
let h2_uri = format!("{}://{}:{}{}",
if pool_key.use_tls { "https" } else { "http" },
pool_key.host, pool_key.port, upstream_path);
let scheme = if pool_key.use_tls { "https" } else { "http" };
let authority = if domain != "-" { domain } else { pool_key.host.as_str() };
let h2_uri = format!("{}://{}{}", scheme, authority, upstream_path);
let mut upstream_req = Request::builder()
.method(method)
.uri(&h2_uri);
@@ -1211,9 +1211,9 @@ impl HttpProxyService {
// Build and send the h2 request inline (don't register in pool yet —
// we need to verify the request actually succeeds first, because some
// backends advertise h2 via ALPN but don't speak the h2 binary protocol).
let h2_uri = format!("{}://{}:{}{}",
if upstream.use_tls { "https" } else { "http" },
upstream.host, upstream.port, upstream_path);
let scheme = if upstream.use_tls { "https" } else { "http" };
let authority = if domain != "-" { domain } else { upstream.host.as_str() };
let h2_uri = format!("{}://{}{}", scheme, authority, upstream_path);
let mut upstream_req = Request::builder()
.method(parts.method)
.uri(&h2_uri);
@@ -1464,13 +1464,12 @@ impl HttpProxyService {
domain: &str,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
// Build absolute URI for H2 pseudo-headers (:scheme, :authority)
let h2_uri = if let Some(pk) = pool_key {
format!("{}://{}:{}{}",
if pk.use_tls { "https" } else { "http" },
pk.host, pk.port, upstream_path)
} else {
upstream_path.to_string()
// Use the requested domain as authority (not backend address) so :authority matches Host header
let scheme = if pool_key.map(|pk| pk.use_tls).unwrap_or(false) { "https" } else { "http" };
let authority = if domain != "-" { domain } else {
pool_key.map(|pk| pk.host.as_str()).unwrap_or("localhost")
};
let h2_uri = format!("{}://{}{}", scheme, authority, upstream_path);
let mut upstream_req = Request::builder()
.method(parts.method)
.uri(&h2_uri);