Fix ForwardedHeaderFilter with non-empty contextPath
Issue: SPR-15088
This commit is contained in:
parent
e78ea34711
commit
df98d304fd
|
@ -262,7 +262,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||||
// Relative to Servlet container root or to current request
|
// Relative to Servlet container root or to current request
|
||||||
String path;
|
String path;
|
||||||
if (location.startsWith(FOLDER_SEPARATOR)) {
|
if (location.startsWith(FOLDER_SEPARATOR)) {
|
||||||
path = this.request.getContextPath() + location;
|
path = location;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
path = StringUtils.applyRelativePath(this.request.getRequestURI(), location);
|
path = StringUtils.applyRelativePath(this.request.getRequestURI(), location);
|
||||||
|
|
|
@ -240,33 +240,10 @@ public class ForwardedHeaderFilterTests {
|
||||||
this.request.addHeader(X_FORWARDED_PORT, "443");
|
this.request.addHeader(X_FORWARDED_PORT, "443");
|
||||||
this.request.setContextPath("/context");
|
this.request.setContextPath("/context");
|
||||||
|
|
||||||
String redirectedUrl = sendRedirect("/foo/bar");
|
String redirectedUrl = sendRedirect("/context/foo/bar");
|
||||||
assertEquals("https://example.com/context/foo/bar", redirectedUrl);
|
assertEquals("https://example.com/context/foo/bar", redirectedUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void sendRedirectWithXForwardedPrefix() throws Exception {
|
|
||||||
this.request.addHeader(X_FORWARDED_PROTO, "https");
|
|
||||||
this.request.addHeader(X_FORWARDED_HOST, "example.com");
|
|
||||||
this.request.addHeader(X_FORWARDED_PORT, "443");
|
|
||||||
this.request.addHeader(X_FORWARDED_PREFIX, "/prefix");
|
|
||||||
|
|
||||||
String redirectedUrl = sendRedirect("/foo/bar");
|
|
||||||
assertEquals("https://example.com/prefix/foo/bar", redirectedUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void sendRedirectWithXForwardedPrefixAndContextPath() throws Exception {
|
|
||||||
this.request.addHeader(X_FORWARDED_PROTO, "https");
|
|
||||||
this.request.addHeader(X_FORWARDED_HOST, "example.com");
|
|
||||||
this.request.addHeader(X_FORWARDED_PORT, "443");
|
|
||||||
this.request.addHeader(X_FORWARDED_PREFIX, "/prefix");
|
|
||||||
this.request.setContextPath("/context");
|
|
||||||
|
|
||||||
String redirectedUrl = sendRedirect("/foo/bar");
|
|
||||||
assertEquals("https://example.com/prefix/foo/bar", redirectedUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendRedirectWithRelativePath() throws Exception {
|
public void sendRedirectWithRelativePath() throws Exception {
|
||||||
this.request.addHeader(X_FORWARDED_PROTO, "https");
|
this.request.addHeader(X_FORWARDED_PROTO, "https");
|
||||||
|
|
Loading…
Reference in New Issue