Support comma-separated X-Forwarded-Proto
Issue: SPR-12816
This commit is contained in:
parent
151e96cac4
commit
f42c53d9be
|
@ -303,7 +303,8 @@ public class UriComponentsBuilder implements Cloneable {
|
||||||
|
|
||||||
String protocolHeader = request.getHeaders().getFirst("X-Forwarded-Proto");
|
String protocolHeader = request.getHeaders().getFirst("X-Forwarded-Proto");
|
||||||
if (StringUtils.hasText(protocolHeader)) {
|
if (StringUtils.hasText(protocolHeader)) {
|
||||||
scheme = protocolHeader;
|
String[] protocols = StringUtils.commaDelimitedListToStringArray(protocolHeader);
|
||||||
|
scheme = protocols[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.scheme(scheme);
|
builder.scheme(scheme);
|
||||||
|
|
|
@ -417,6 +417,25 @@ public class UriComponentsBuilderTests {
|
||||||
assertEquals("http://a.example.org/mvc-showcase", result.toString());
|
assertEquals("http://a.example.org/mvc-showcase", result.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPR-12816
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromHttpRequestWithForwardedProtoMultiValueHeader() {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
request.setScheme("http");
|
||||||
|
request.setServerName("localhost");
|
||||||
|
request.setServerPort(8080);
|
||||||
|
request.setRequestURI("/mvc-showcase");
|
||||||
|
request.addHeader("X-Forwarded-Host", "a.example.org");
|
||||||
|
request.addHeader("X-Forwarded-Port", "443");
|
||||||
|
request.addHeader("X-Forwarded-Proto", "https,https");
|
||||||
|
|
||||||
|
HttpRequest httpRequest = new ServletServerHttpRequest(request);
|
||||||
|
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
|
||||||
|
|
||||||
|
assertEquals("https://a.example.org/mvc-showcase", result.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void path() throws URISyntaxException {
|
public void path() throws URISyntaxException {
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");
|
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");
|
||||||
|
|
Loading…
Reference in New Issue