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

UNDERTOW-1807: Fix ForwardedHandlerTestCase on jdk14+ #992

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,6 +21,7 @@
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import static io.undertow.server.handlers.ForwardedHandler.parseAddress;
import static io.undertow.server.handlers.ForwardedHandler.parseHeader;
Expand All @@ -37,11 +38,25 @@ public static void setup() {
DefaultServer.setRootHandler(new ForwardedHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseSender().send(exchange.getRequestScheme() + "|" + exchange.getHostAndPort()+ "|" + exchange.getDestinationAddress() + "|" + exchange.getSourceAddress() );
exchange.getResponseSender().send(
exchange.getRequestScheme()
+ "|" + exchange.getHostAndPort()
+ "|" + toJreNormalizedString(exchange.getDestinationAddress())
+ "|" + toJreNormalizedString(exchange.getSourceAddress()));
}
}));
}

private static String toJreNormalizedString(InetSocketAddress address) {
// https://mail.openjdk.java.net/pipermail/net-dev/2019-June/012741.html
// https://bugs.openjdk.java.net/browse/JDK-8225499
// Java 14 introduced a new component to the toString value to disambiguate ipv6 values
return Objects.toString(address)
.replace("/<unresolved>", "")
.replace("[", "")
.replace("]", "");
}

@Test
public void testHeaderParsing() {
Map<ForwardedHandler.Token, String> results = new HashMap<>();
Expand Down