Full "Forwarded" header support including port number

Issue: SPR-15504
This commit is contained in:
Gregory Vandenbroucke
2017-04-28 20:36:13 +02:00
committed by Rossen Stoyanchev
parent 2ccf78743a
commit ec55e429f0
2 changed files with 65 additions and 1 deletions

View File

@@ -717,7 +717,16 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
String forwardedToUse = StringUtils.tokenizeToStringArray(forwardedHeader, ",")[0];
Matcher matcher = FORWARDED_HOST_PATTERN.matcher(forwardedToUse);
if (matcher.find()) {
host(matcher.group(1).trim());
String hostToUse = matcher.group(1).trim();
int portSeparatorIdx = hostToUse.lastIndexOf(":");
if (portSeparatorIdx > hostToUse.lastIndexOf("]")) {
host(hostToUse.substring(0, portSeparatorIdx));
port(Integer.parseInt(hostToUse.substring(portSeparatorIdx + 1)));
}
else {
host(hostToUse);
port(null);
}
}
matcher = FORWARDED_PROTO_PATTERN.matcher(forwardedToUse);
if (matcher.find()) {