Source:
<code>public void handleRequest(HttpServerExchange exchange) throws Exception { String forwardedFor = exchange.getRequestHeaders().getFirst(Headers.X_FORWARDED_FOR); if (forwardedFor != null) { int index = forwardedFor.indexOf(','); final String value; if (index == -1) { value = forwardedFor; } else { value = forwardedFor.substring(0, index); } exchange.setSourceAddress(InetSocketAddress.createUnresolved(value, 0)); } String forwardedProto = exchange.getRequestHeaders().getFirst(Headers.X_FORWARDED_PROTO); if (forwardedProto != null) { exchange.setRequestScheme(forwardedProto); } String forwardedHost = exchange.getRequestHeaders().getFirst(Headers.X_FORWARDED_HOST); String forwardedPort = exchange.getRequestHeaders().getFirst(Headers.X_FORWARDED_PORT); if (forwardedHost != null) { int index = forwardedHost.indexOf(','); String value; if (index == -1) { value = forwardedHost; } else { value = forwardedHost.substring(0, index); } if(value.startsWith("[")) { int end = value.lastIndexOf("]"); if(end == -1 ) { end = 0; } index = value.indexOf(":", end); if(index != -1) { forwardedPort = value.substring(index + 1); value = value.substring(0, index); } } else { index = value.lastIndexOf(":"); if(index != -1) { forwardedPort = value.substring(index + 1); value = value.substring(0, index); } } int port = 0; if(forwardedPort != null) { try { port = Integer.parseInt(forwardedPort); } catch (NumberFormatException ignore) { UndertowLogger.REQUEST_LOGGER.debugf("Cannot parse port: %s", forwardedPort); } } String hostHeader = NetworkUtils.formatPossibleIpv6Address(value); <START> if (port != 0) <END> hostHeader += ":" + port; exchange.getRequestHeaders().put(Headers.HOST, hostHeader); exchange.setDestinationAddress(InetSocketAddress.createUnresolved(value, port)); } next.handleRequest(exchange); }</code><technical_language>this is pretty true</technical_language>

Target:
public void handleRequest(HttpServerExchange exchange) throws Exception { String forwardedFor = exchange.getRequestHeaders().getFirst(Headers.X_FORWARDED_FOR); if (forwardedFor != null) { int index = forwardedFor.indexOf(','); final String value; if (index == -1) { value = forwardedFor; } else { value = forwardedFor.substring(0, index); } exchange.setSourceAddress(InetSocketAddress.createUnresolved(value, 0)); } String forwardedProto = exchange.getRequestHeaders().getFirst(Headers.X_FORWARDED_PROTO); if (forwardedProto != null) { exchange.setRequestScheme(forwardedProto); } String forwardedHost = exchange.getRequestHeaders().getFirst(Headers.X_FORWARDED_HOST); String forwardedPort = exchange.getRequestHeaders().getFirst(Headers.X_FORWARDED_PORT); if (forwardedHost != null) { int index = forwardedHost.indexOf(','); String value; if (index == -1) { value = forwardedHost; } else { value = forwardedHost.substring(0, index); } if(value.startsWith("[")) { int end = value.lastIndexOf("]"); if(end == -1 ) { end = 0; } index = value.indexOf(":", end); if(index != -1) { forwardedPort = value.substring(index + 1); value = value.substring(0, index); } } else { index = value.lastIndexOf(":"); if(index != -1) { forwardedPort = value.substring(index + 1); value = value.substring(0, index); } } int port = 0; String hostHeader = NetworkUtils.formatPossibleIpv6Address(value); if(forwardedPort != null) { try { port = Integer.parseInt(forwardedPort); hostHeader += ":" + port; } catch (NumberFormatException ignore) { UndertowLogger.REQUEST_LOGGER.debugf("Cannot parse port: %s", forwardedPort); } } exchange.getRequestHeaders().put(Headers.HOST, hostHeader); exchange.setDestinationAddress(InetSocketAddress.createUnresolved(value, port)); } next.handleRequest(exchange); }