From 8b1f641819927a6022ea29a5c2bf551f6ee29c81 Mon Sep 17 00:00:00 2001 From: Clement Escoffier Date: Tue, 20 Aug 2024 14:00:27 +0200 Subject: [PATCH] Use the `Host` header in a proxies response instead of `host` See https://github.com/quarkusio/quarkus/issues/42367 --- .../io/quarkus/vertx/http/runtime/ForwardedParser.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/ForwardedParser.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/ForwardedParser.java index b768c4c6cddfc..95be0431ee84e 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/ForwardedParser.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/ForwardedParser.java @@ -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; @@ -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; @@ -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); } @@ -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); }