ForwardedHeaderFilter requestURI preserve encoding
Previously ForwardedHeaderFilter would override the requestURI with a URL decoded value. This would cause problems when using a URL encoded requestURI since downstream Filters would not see the URL encoded value as they should. This commit resolves this issue by ensuring that the requestURI is properly encoded. Issues SPR-15422
This commit is contained in:
parent
d098a4b96b
commit
84db06ec0b
|
|
@ -69,7 +69,12 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
|||
}
|
||||
|
||||
|
||||
private final UrlPathHelper pathHelper = new UrlPathHelper();
|
||||
private final UrlPathHelper pathHelper;
|
||||
|
||||
public ForwardedHeaderFilter() {
|
||||
this.pathHelper = new UrlPathHelper();
|
||||
this.pathHelper.setUrlDecode(false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -106,6 +106,18 @@ public class ForwardedHeaderFilterTests {
|
|||
assertEquals("", actual.getContextPath());
|
||||
assertEquals("/path/", actual.getRequestURI());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestUriPreserveEncoding() throws Exception {
|
||||
this.request.setContextPath("/app");
|
||||
this.request.setRequestURI("/app/path%20with%20spaces/");
|
||||
HttpServletRequest actual = filterAndGetWrappedRequest();
|
||||
|
||||
assertEquals("/app", actual.getContextPath());
|
||||
assertEquals("/app/path%20with%20spaces/", actual.getRequestURI());
|
||||
assertEquals("http://localhost/app/path%20with%20spaces/", actual.getRequestURL().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestUriEqualsContextPath() throws Exception {
|
||||
this.request.addHeader(X_FORWARDED_PREFIX, "/");
|
||||
|
|
|
|||
Loading…
Reference in New Issue