Also apply X-Forwarded-Prefix in fromContextPath

Issue: SPR-12500
This commit is contained in:
Rossen Stoyanchev
2014-12-04 10:15:55 -05:00
parent 9ef0bdcb17
commit 7f11c1ee2f
2 changed files with 33 additions and 7 deletions

View File

@@ -176,6 +176,15 @@ public class ServletUriComponentsBuilderTests {
assertEquals("http://localhost/mvc-showcase", result);
}
@Test
public void fromContextPathWithForwardedPrefix() {
request.addHeader("X-Forwarded-Prefix", "/prefix");
request.setContextPath("/mvc-showcase");
request.setRequestURI("/mvc-showcase/simple");
String result = ServletUriComponentsBuilder.fromContextPath(request).build().toUriString();
assertEquals("http://localhost/prefix/mvc-showcase", result);
}
@Test
public void fromServletMapping() {
request.setRequestURI("/mvc-showcase/app/simple");
@@ -185,6 +194,16 @@ public class ServletUriComponentsBuilderTests {
assertEquals("http://localhost/mvc-showcase/app", result);
}
@Test
public void fromServletMappingWithForwardedPrefix() {
request.addHeader("X-Forwarded-Prefix", "/prefix");
request.setContextPath("/mvc-showcase");
request.setServletPath("/app");
request.setRequestURI("/mvc-showcase/app/simple");
String result = ServletUriComponentsBuilder.fromServletMapping(request).build().toUriString();
assertEquals("http://localhost/prefix/mvc-showcase/app", result);
}
@Test
public void fromCurrentRequest() {
request.setRequestURI("/mvc-showcase/data/param");