Support X-Forwarded-Ssl

Issue: SPR-16863
This commit is contained in:
Rossen Stoyanchev
2018-05-24 16:14:12 -04:00
parent 85e8634810
commit 3eac2dd31e
3 changed files with 30 additions and 1 deletions

View File

@@ -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(']')) {