Skip to content
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

Use the Host header in a proxied responses instead of host #42648

Merged
merged 1 commit into from
Aug 20, 2024
Merged
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
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
Loading