Skip to content

Commit df98d30

Browse files
author
Rob Winch
committed
Fix ForwardedHeaderFilter with non-empty contextPath
Issue: SPR-15088
1 parent e78ea34 commit df98d30

File tree

2 files changed

+2
-25
lines changed

2 files changed

+2
-25
lines changed

spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public void sendRedirect(String location) throws IOException {
262262
// Relative to Servlet container root or to current request
263263
String path;
264264
if (location.startsWith(FOLDER_SEPARATOR)) {
265-
path = this.request.getContextPath() + location;
265+
path = location;
266266
}
267267
else {
268268
path = StringUtils.applyRelativePath(this.request.getRequestURI(), location);

spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -240,33 +240,10 @@ public void sendRedirectWithContextPath() throws Exception {
240240
this.request.addHeader(X_FORWARDED_PORT, "443");
241241
this.request.setContextPath("/context");
242242

243-
String redirectedUrl = sendRedirect("/foo/bar");
243+
String redirectedUrl = sendRedirect("/context/foo/bar");
244244
assertEquals("https://example.com/context/foo/bar", redirectedUrl);
245245
}
246246

247-
@Test
248-
public void sendRedirectWithXForwardedPrefix() throws Exception {
249-
this.request.addHeader(X_FORWARDED_PROTO, "https");
250-
this.request.addHeader(X_FORWARDED_HOST, "example.com");
251-
this.request.addHeader(X_FORWARDED_PORT, "443");
252-
this.request.addHeader(X_FORWARDED_PREFIX, "/prefix");
253-
254-
String redirectedUrl = sendRedirect("/foo/bar");
255-
assertEquals("https://example.com/prefix/foo/bar", redirectedUrl);
256-
}
257-
258-
@Test
259-
public void sendRedirectWithXForwardedPrefixAndContextPath() throws Exception {
260-
this.request.addHeader(X_FORWARDED_PROTO, "https");
261-
this.request.addHeader(X_FORWARDED_HOST, "example.com");
262-
this.request.addHeader(X_FORWARDED_PORT, "443");
263-
this.request.addHeader(X_FORWARDED_PREFIX, "/prefix");
264-
this.request.setContextPath("/context");
265-
266-
String redirectedUrl = sendRedirect("/foo/bar");
267-
assertEquals("https://example.com/prefix/foo/bar", redirectedUrl);
268-
}
269-
270247
@Test
271248
public void sendRedirectWithRelativePath() throws Exception {
272249
this.request.addHeader(X_FORWARDED_PROTO, "https");

0 commit comments

Comments
 (0)