Rename contextPath method in ForwardedHeaderFilter

This commit is contained in:
Rossen Stoyanchev 2016-06-01 15:45:44 -04:00
parent b7f589547d
commit c74d979735
2 changed files with 22 additions and 16 deletions

View File

@ -72,16 +72,22 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
/**
* Configure a contextPath value that will replace the contextPath of
* proxy-forwarded requests.
* <p>This is useful when external clients are not aware of the application
* context path. However a proxy forwards the request to a URL that includes
* a contextPath.
* Configure a contextPath override that will replace the contextPath of
* proxy-forwarded requests. This is useful when external clients are not
* aware of the application context path to which the proxy is configured
* to forward to.
*
* <p>For example, a client may connect to a proxy at:<br>
* {@code https://example.com/}
*
* <p>In turn the proxy forwards to the application at:<br>
* {@code 192.168.1.1:8080/example/}
*
* @param contextPath the context path; the given value will be sanitized to
* ensure it starts with a '/' but does not end with one, or if the context
* path is empty (default, root context) it is left as-is.
*/
public void setContextPath(String contextPath) {
public void setContextPathOverride(String contextPath) {
Assert.notNull(contextPath, "'contextPath' must not be null");
this.contextPathHelper = new ContextPathHelper(contextPath);
}

View File

@ -59,42 +59,42 @@ public class ForwardedHeaderFilterTests {
@Test(expected = IllegalArgumentException.class)
public void contextPathNull() {
this.filter.setContextPath(null);
this.filter.setContextPathOverride(null);
}
@Test
public void contextPathEmpty() throws Exception {
this.filter.setContextPath("");
this.filter.setContextPathOverride("");
assertEquals("", filterAndGetContextPath());
}
@Test
public void contextPathWithExtraSpaces() throws Exception {
this.filter.setContextPath(" /foo ");
this.filter.setContextPathOverride(" /foo ");
assertEquals("/foo", filterAndGetContextPath());
}
@Test
public void contextPathWithNoLeadingSlash() throws Exception {
this.filter.setContextPath("foo");
this.filter.setContextPathOverride("foo");
assertEquals("/foo", filterAndGetContextPath());
}
@Test
public void contextPathWithTrailingSlash() throws Exception {
this.filter.setContextPath("/foo/bar/");
this.filter.setContextPathOverride("/foo/bar/");
assertEquals("/foo/bar", filterAndGetContextPath());
}
@Test
public void contextPathWithTrailingSlashes() throws Exception {
this.filter.setContextPath("/foo/bar/baz///");
this.filter.setContextPathOverride("/foo/bar/baz///");
assertEquals("/foo/bar/baz", filterAndGetContextPath());
}
@Test
public void requestUri() throws Exception {
this.filter.setContextPath("/");
this.filter.setContextPathOverride("/");
this.request.setContextPath("/app");
this.request.setRequestURI("/app/path");
HttpServletRequest actual = filterAndGetWrappedRequest();
@ -105,7 +105,7 @@ public class ForwardedHeaderFilterTests {
@Test
public void requestUriWithTrailingSlash() throws Exception {
this.filter.setContextPath("/");
this.filter.setContextPathOverride("/");
this.request.setContextPath("/app");
this.request.setRequestURI("/app/path/");
HttpServletRequest actual = filterAndGetWrappedRequest();
@ -115,7 +115,7 @@ public class ForwardedHeaderFilterTests {
}
@Test
public void requestUriEqualsContextPath() throws Exception {
this.filter.setContextPath("/");
this.filter.setContextPathOverride("/");
this.request.setContextPath("/app");
this.request.setRequestURI("/app");
HttpServletRequest actual = filterAndGetWrappedRequest();
@ -126,7 +126,7 @@ public class ForwardedHeaderFilterTests {
@Test
public void requestUriRootUrl() throws Exception {
this.filter.setContextPath("/");
this.filter.setContextPathOverride("/");
this.request.setContextPath("/app");
this.request.setRequestURI("/app/");
HttpServletRequest actual = filterAndGetWrappedRequest();