From c74d979735e18888936e3d1b7a5e283501edb8c6 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 1 Jun 2016 15:45:44 -0400 Subject: [PATCH] Rename contextPath method in ForwardedHeaderFilter --- .../web/filter/ForwardedHeaderFilter.java | 18 +++++++++++------ .../filter/ForwardedHeaderFilterTests.java | 20 +++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java index ba2ad448c6..25225d74ba 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java @@ -72,16 +72,22 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { /** - * Configure a contextPath value that will replace the contextPath of - * proxy-forwarded requests. - *

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. + * + *

For example, a client may connect to a proxy at:
+ * {@code https://example.com/} + * + *

In turn the proxy forwards to the application at:
+ * {@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); } diff --git a/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java index 4c9c45256f..ef6ed2e955 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java @@ -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();