Browse Source

Consistently remove forwarded headers in WebFlux

Preparation for SPR-17072
pull/1895/merge
Rossen Stoyanchev 6 years ago
parent
commit
2e4f5a7923
  1. 1
      spring-web/src/main/java/org/springframework/web/filter/reactive/ForwardedHeaderFilter.java
  2. 4
      spring-web/src/test/java/org/springframework/web/filter/reactive/ForwardedHeaderFilterTests.java

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

@ -91,6 +91,7 @@ public class ForwardedHeaderFilter implements WebFilter { @@ -91,6 +91,7 @@ public class ForwardedHeaderFilter implements WebFilter {
builder.path(prefix + uri.getPath());
builder.contextPath(prefix);
}
removeForwardedHeaders(builder);
})
.build();
}

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

@ -74,6 +74,7 @@ public class ForwardedHeaderFilterTests { @@ -74,6 +74,7 @@ public class ForwardedHeaderFilterTests {
this.filter.filter(getExchange(headers), this.filterChain).block(Duration.ZERO);
assertEquals(new URI("https://84.198.58.199/path"), this.filterChain.uri);
this.filterChain.assertForwardedHeadersRemoved();
}
@Test
@ -83,6 +84,7 @@ public class ForwardedHeaderFilterTests { @@ -83,6 +84,7 @@ public class ForwardedHeaderFilterTests {
this.filter.filter(getExchange(headers), this.filterChain).block(Duration.ZERO);
assertEquals(new URI("https://84.198.58.199/path"), this.filterChain.uri);
this.filterChain.assertForwardedHeadersRemoved();
}
@Test
@ -93,6 +95,7 @@ public class ForwardedHeaderFilterTests { @@ -93,6 +95,7 @@ public class ForwardedHeaderFilterTests {
assertEquals(new URI("http://example.com/prefix/path"), this.filterChain.uri);
assertEquals("/prefix/path", this.filterChain.requestPathValue);
this.filterChain.assertForwardedHeadersRemoved();
}
@Test
@ -103,6 +106,7 @@ public class ForwardedHeaderFilterTests { @@ -103,6 +106,7 @@ public class ForwardedHeaderFilterTests {
assertEquals(new URI("http://example.com/prefix/path"), this.filterChain.uri);
assertEquals("/prefix/path", this.filterChain.requestPathValue);
this.filterChain.assertForwardedHeadersRemoved();
}
private MockServerWebExchange getExchange(HttpHeaders headers) {

Loading…
Cancel
Save