Polish
This commit is contained in:
parent
ec55e429f0
commit
056284b407
|
|
@ -717,16 +717,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||||
String forwardedToUse = StringUtils.tokenizeToStringArray(forwardedHeader, ",")[0];
|
String forwardedToUse = StringUtils.tokenizeToStringArray(forwardedHeader, ",")[0];
|
||||||
Matcher matcher = FORWARDED_HOST_PATTERN.matcher(forwardedToUse);
|
Matcher matcher = FORWARDED_HOST_PATTERN.matcher(forwardedToUse);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
String hostToUse = matcher.group(1).trim();
|
adaptForwardedHost(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);
|
matcher = FORWARDED_PROTO_PATTERN.matcher(forwardedToUse);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
|
|
@ -736,16 +727,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||||
else {
|
else {
|
||||||
String hostHeader = headers.getFirst("X-Forwarded-Host");
|
String hostHeader = headers.getFirst("X-Forwarded-Host");
|
||||||
if (StringUtils.hasText(hostHeader)) {
|
if (StringUtils.hasText(hostHeader)) {
|
||||||
String hostToUse = StringUtils.tokenizeToStringArray(hostHeader, ",")[0];
|
adaptForwardedHost(StringUtils.tokenizeToStringArray(hostHeader, ",")[0]);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String portHeader = headers.getFirst("X-Forwarded-Port");
|
String portHeader = headers.getFirst("X-Forwarded-Port");
|
||||||
|
|
@ -767,6 +749,18 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void adaptForwardedHost(String hostToUse) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void resetHierarchicalComponents() {
|
private void resetHierarchicalComponents() {
|
||||||
this.userInfo = null;
|
this.userInfo = null;
|
||||||
this.host = null;
|
this.host = null;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue