Skip to content

Commit

Permalink
Use the Host header in a proxies response instead of host
Browse files Browse the repository at this point in the history
See #42367

(cherry picked from commit 8b1f641)
  • Loading branch information
cescoffier authored and gsmet committed Aug 20, 2024
1 parent 6f36035 commit 39319e7
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.jboss.logging.Logger;

import io.netty.util.AsciiString;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.net.HostAndPort;
import io.vertx.core.net.SocketAddress;
Expand Down Expand Up @@ -53,6 +52,11 @@ class ForwardedParser {
private final ForwardingProxyOptions forwardingProxyOptions;
private final TrustedProxyCheck trustedProxyCheck;

/**
* Does not use the Netty constant (`host`) to enforce the header name convention.
*/
private final static AsciiString HOST_HEADER = AsciiString.cached("Host");

private boolean calculated;
private String host;
private int port = -1;
Expand Down Expand Up @@ -188,7 +192,7 @@ private void calculate() {

authority = HostAndPort.create(host, port >= 0 ? port : -1);
host = host + (port >= 0 ? ":" + port : "");
delegate.headers().set(HttpHeaders.HOST, host);
delegate.headers().set(HOST_HEADER, host);
absoluteURI = scheme + "://" + host + uri;
log.debug("Recalculated absoluteURI to " + absoluteURI);
}
Expand All @@ -199,7 +203,7 @@ private void setHostAndPort(String hostToParse, int defaultPort) {
}
String[] hostAndPort = parseHostAndPort(hostToParse);
host = hostAndPort[0];
delegate.headers().set(HttpHeaders.HOST, host);
delegate.headers().set(HOST_HEADER, host);
port = parsePort(hostAndPort[1], defaultPort);
}

Expand Down

0 comments on commit 39319e7

Please sign in to comment.