Rename contextPath method in ForwardedHeaderFilter
This commit is contained in:
parent
b7f589547d
commit
c74d979735
|
@ -72,16 +72,22 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure a contextPath value that will replace the contextPath of
|
* Configure a contextPath override that will replace the contextPath of
|
||||||
* proxy-forwarded requests.
|
* proxy-forwarded requests. This is useful when external clients are not
|
||||||
* <p>This is useful when external clients are not aware of the application
|
* aware of the application context path to which the proxy is configured
|
||||||
* context path. However a proxy forwards the request to a URL that includes
|
* to forward to.
|
||||||
* a contextPath.
|
*
|
||||||
|
* <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
|
* @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
|
* 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.
|
* 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");
|
Assert.notNull(contextPath, "'contextPath' must not be null");
|
||||||
this.contextPathHelper = new ContextPathHelper(contextPath);
|
this.contextPathHelper = new ContextPathHelper(contextPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,42 +59,42 @@ public class ForwardedHeaderFilterTests {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void contextPathNull() {
|
public void contextPathNull() {
|
||||||
this.filter.setContextPath(null);
|
this.filter.setContextPathOverride(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextPathEmpty() throws Exception {
|
public void contextPathEmpty() throws Exception {
|
||||||
this.filter.setContextPath("");
|
this.filter.setContextPathOverride("");
|
||||||
assertEquals("", filterAndGetContextPath());
|
assertEquals("", filterAndGetContextPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextPathWithExtraSpaces() throws Exception {
|
public void contextPathWithExtraSpaces() throws Exception {
|
||||||
this.filter.setContextPath(" /foo ");
|
this.filter.setContextPathOverride(" /foo ");
|
||||||
assertEquals("/foo", filterAndGetContextPath());
|
assertEquals("/foo", filterAndGetContextPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextPathWithNoLeadingSlash() throws Exception {
|
public void contextPathWithNoLeadingSlash() throws Exception {
|
||||||
this.filter.setContextPath("foo");
|
this.filter.setContextPathOverride("foo");
|
||||||
assertEquals("/foo", filterAndGetContextPath());
|
assertEquals("/foo", filterAndGetContextPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextPathWithTrailingSlash() throws Exception {
|
public void contextPathWithTrailingSlash() throws Exception {
|
||||||
this.filter.setContextPath("/foo/bar/");
|
this.filter.setContextPathOverride("/foo/bar/");
|
||||||
assertEquals("/foo/bar", filterAndGetContextPath());
|
assertEquals("/foo/bar", filterAndGetContextPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextPathWithTrailingSlashes() throws Exception {
|
public void contextPathWithTrailingSlashes() throws Exception {
|
||||||
this.filter.setContextPath("/foo/bar/baz///");
|
this.filter.setContextPathOverride("/foo/bar/baz///");
|
||||||
assertEquals("/foo/bar/baz", filterAndGetContextPath());
|
assertEquals("/foo/bar/baz", filterAndGetContextPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestUri() throws Exception {
|
public void requestUri() throws Exception {
|
||||||
this.filter.setContextPath("/");
|
this.filter.setContextPathOverride("/");
|
||||||
this.request.setContextPath("/app");
|
this.request.setContextPath("/app");
|
||||||
this.request.setRequestURI("/app/path");
|
this.request.setRequestURI("/app/path");
|
||||||
HttpServletRequest actual = filterAndGetWrappedRequest();
|
HttpServletRequest actual = filterAndGetWrappedRequest();
|
||||||
|
@ -105,7 +105,7 @@ public class ForwardedHeaderFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestUriWithTrailingSlash() throws Exception {
|
public void requestUriWithTrailingSlash() throws Exception {
|
||||||
this.filter.setContextPath("/");
|
this.filter.setContextPathOverride("/");
|
||||||
this.request.setContextPath("/app");
|
this.request.setContextPath("/app");
|
||||||
this.request.setRequestURI("/app/path/");
|
this.request.setRequestURI("/app/path/");
|
||||||
HttpServletRequest actual = filterAndGetWrappedRequest();
|
HttpServletRequest actual = filterAndGetWrappedRequest();
|
||||||
|
@ -115,7 +115,7 @@ public class ForwardedHeaderFilterTests {
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void requestUriEqualsContextPath() throws Exception {
|
public void requestUriEqualsContextPath() throws Exception {
|
||||||
this.filter.setContextPath("/");
|
this.filter.setContextPathOverride("/");
|
||||||
this.request.setContextPath("/app");
|
this.request.setContextPath("/app");
|
||||||
this.request.setRequestURI("/app");
|
this.request.setRequestURI("/app");
|
||||||
HttpServletRequest actual = filterAndGetWrappedRequest();
|
HttpServletRequest actual = filterAndGetWrappedRequest();
|
||||||
|
@ -126,7 +126,7 @@ public class ForwardedHeaderFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestUriRootUrl() throws Exception {
|
public void requestUriRootUrl() throws Exception {
|
||||||
this.filter.setContextPath("/");
|
this.filter.setContextPathOverride("/");
|
||||||
this.request.setContextPath("/app");
|
this.request.setContextPath("/app");
|
||||||
this.request.setRequestURI("/app/");
|
this.request.setRequestURI("/app/");
|
||||||
HttpServletRequest actual = filterAndGetWrappedRequest();
|
HttpServletRequest actual = filterAndGetWrappedRequest();
|
||||||
|
|
Loading…
Reference in New Issue