Support X-Forwarded-Ssl
Issue: SPR-16863
This commit is contained in:
@@ -743,6 +743,10 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
scheme(matcher.group(1).trim());
|
||||
port(null);
|
||||
}
|
||||
else if (isForwardedSslOn(headers)) {
|
||||
scheme("https");
|
||||
port(null);
|
||||
}
|
||||
matcher = FORWARDED_HOST_PATTERN.matcher(forwardedToUse);
|
||||
if (matcher.find()) {
|
||||
adaptForwardedHost(matcher.group(1).trim());
|
||||
@@ -754,6 +758,10 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
scheme(StringUtils.tokenizeToStringArray(protocolHeader, ",")[0]);
|
||||
port(null);
|
||||
}
|
||||
else if (isForwardedSslOn(headers)) {
|
||||
scheme("https");
|
||||
port(null);
|
||||
}
|
||||
|
||||
String hostHeader = headers.getFirst("X-Forwarded-Host");
|
||||
if (StringUtils.hasText(hostHeader)) {
|
||||
@@ -780,6 +788,11 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean isForwardedSslOn(HttpHeaders headers) {
|
||||
String forwardedSsl = headers.getFirst("X-Forwarded-Ssl");
|
||||
return StringUtils.hasText(forwardedSsl) && forwardedSsl.equalsIgnoreCase("on");
|
||||
}
|
||||
|
||||
private void adaptForwardedHost(String hostToUse) {
|
||||
int portSeparatorIdx = hostToUse.lastIndexOf(':');
|
||||
if (portSeparatorIdx > hostToUse.lastIndexOf(']')) {
|
||||
|
||||
Reference in New Issue
Block a user