-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: X-Forwarded-Prefix not working when using MVC #3443
base: main
Are you sure you want to change the base?
Changes from all commits
39c6237
c33aeea
2e4552d
279af98
bad0448
713e57c
5bd5c61
d2b8c6b
2b2f1d5
c682aa5
fbe943c
9852de1
0747ad4
2f8a33a
9432657
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,6 +248,14 @@ public void stripPrefixWorks() { | |
.consumeWith(res -> { | ||
Map<String, Object> map = res.getResponseBody(); | ||
Map<String, Object> headers = getMap(map, "headers"); | ||
assertThat(headers).containsKeys( | ||
XForwardedRequestHeadersFilter.X_FORWARDED_PREFIX_HEADER, | ||
XForwardedRequestHeadersFilter.X_FORWARDED_HOST_HEADER, | ||
XForwardedRequestHeadersFilter.X_FORWARDED_PORT_HEADER, | ||
XForwardedRequestHeadersFilter.X_FORWARDED_PROTO_HEADER, | ||
XForwardedRequestHeadersFilter.X_FORWARDED_FOR_HEADER); | ||
assertThat(headers).containsEntry( | ||
XForwardedRequestHeadersFilter.X_FORWARDED_PREFIX_HEADER, "/long/path/to"); | ||
assertThat(headers).containsEntry("X-Test", "stripPrefix"); | ||
}); | ||
} | ||
|
@@ -266,6 +274,14 @@ public void stripPrefixPostWorks() { | |
Map<String, Object> map = res.getResponseBody(); | ||
assertThat(map).containsEntry("data", "hello"); | ||
Map<String, Object> headers = getMap(map, "headers"); | ||
assertThat(headers).containsKeys( | ||
XForwardedRequestHeadersFilter.X_FORWARDED_PREFIX_HEADER, | ||
XForwardedRequestHeadersFilter.X_FORWARDED_HOST_HEADER, | ||
XForwardedRequestHeadersFilter.X_FORWARDED_PORT_HEADER, | ||
XForwardedRequestHeadersFilter.X_FORWARDED_PROTO_HEADER, | ||
XForwardedRequestHeadersFilter.X_FORWARDED_FOR_HEADER); | ||
assertThat(headers).containsEntry( | ||
XForwardedRequestHeadersFilter.X_FORWARDED_PREFIX_HEADER, "/long/path/to"); | ||
assertThat(headers).containsEntry("X-Test", "stripPrefixPost"); | ||
}); | ||
} | ||
|
@@ -1080,9 +1096,9 @@ public RouterFunction<ServerResponse> gatewayRouterFunctionsSetPathPost() { | |
public RouterFunction<ServerResponse> gatewayRouterFunctionsStripPrefix() { | ||
// @formatter:off | ||
return route(GET("/long/path/to/get"), http()) | ||
.filter(new HttpbinUriResolver()) | ||
.filter(stripPrefix(3)) | ||
.filter(addRequestHeader("X-Test", "stripPrefix")) | ||
.filter(new HttpbinUriResolver(true)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Help me understand why this is needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, I can't quite remember the details of why I had to do this as it's been a while since I worked on this. I was struggling getting tests to pass, despite believing that they should. The return URI.create(String.format("http://%s:%d", host, port)); and since that was earlier in the filter chain than For the I may be going completely down the wrong path here, but I'm convinced that either I'm doing something wrong or something is not quite right. I'd appreciate any pointers for getting these two tests correct |
||
.withAttribute(MvcUtils.GATEWAY_ROUTE_ID_ATTR, "teststripprefix"); | ||
// @formatter:on | ||
} | ||
|
@@ -1092,9 +1108,9 @@ public RouterFunction<ServerResponse> gatewayRouterFunctionsStripPrefixPost() { | |
// @formatter:off | ||
return route("teststripprefixpost") | ||
.route(POST("/long/path/to/post").and(host("**.stripprefixpost.org")), http()) | ||
.filter(new HttpbinUriResolver()) | ||
.filter(stripPrefix(3)) | ||
.filter(addRequestHeader("X-Test", "stripPrefixPost")) | ||
.filter(new HttpbinUriResolver(true)) | ||
.build(); | ||
// @formatter:on | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the value here without the fix?
/get
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the fix, the header is missing entirely. I believe this is the bug as raised in the original issue. The
X-Forwarded-Prefix
header is missing when using MVC, but it is present when using Reactive/WebFlux