11/*
2- * Copyright (c) 2020-2021 VMware, Inc. or its affiliates, All Rights Reserved.
2+ * Copyright (c) 2020-2023 VMware, Inc. or its affiliates, All Rights Reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -89,8 +89,10 @@ private ConnectionInfo parseXForwardedInfo(ConnectionInfo connectionInfo, HttpRe
8989 }
9090 String hostHeader = request .headers ().get (X_FORWARDED_HOST_HEADER );
9191 if (hostHeader != null ) {
92- String portHeader = request .headers ().get (X_FORWARDED_PORT_HEADER );
9392 int port = connectionInfo .getHostAddress ().getPort ();
93+ connectionInfo = connectionInfo .withHostAddress (
94+ AddressUtils .parseAddress (hostHeader .split ("," , 2 )[0 ].trim (), port , DEFAULT_FORWARDED_HEADER_VALIDATION ));
95+ String portHeader = request .headers ().get (X_FORWARDED_PORT_HEADER );
9496 if (portHeader != null && !portHeader .isEmpty ()) {
9597 String portStr = portHeader .split ("," , 2 )[0 ].trim ();
9698 if (portStr .chars ().allMatch (Character ::isDigit )) {
@@ -99,9 +101,9 @@ private ConnectionInfo parseXForwardedInfo(ConnectionInfo connectionInfo, HttpRe
99101 else if (DEFAULT_FORWARDED_HEADER_VALIDATION ) {
100102 throw new IllegalArgumentException ("Failed to parse a port from " + portHeader );
101103 }
104+ connectionInfo = connectionInfo .withHostAddress (
105+ AddressUtils .createUnresolved (connectionInfo .getHostAddress ().getHostString (), port ));
102106 }
103- connectionInfo = connectionInfo .withHostAddress (
104- AddressUtils .createUnresolved (hostHeader .split ("," , 2 )[0 ].trim (), port ));
105107 }
106108 String protoHeader = request .headers ().get (X_FORWARDED_PROTO_HEADER );
107109 if (protoHeader != null ) {
0 commit comments