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
WebFlux application server add server.forward- Headers - Strategy = Framework RouterFunction endpoint 404 #25270
Comments
Issue summary
The problem here, with this setup, only the annotated one works and the functional one does not map. Spring Cloud Gateway and Forwarded headersFirst, you've configured your Spring Cloud Gateway application to strip the Since you've added the ForwardedHeaderTransformer behaviorSo at that point, we know that with this configuration your
So the filters removes the forwarded headers and takes the prefix as the context path for the request. Mapping behavior for WebFlux annotated/functional endpointsNow you might wonder why the WebFlux annotated controller This explains why with this setup the annotated endpoint is properly routed and the functional one is not. One could argue that this setup is flawed in the first place with the Now I'm also wondering why there's that mapping behavior difference between annotated controllers and functional endpoints in WebFlux. Why is the context path taken into account in one case and not other? Could you help us here @rstoyanchev and @poutsma ? |
@bclozel Thanks for your quick reply
Configure The following link explains more information |
I see, thanks! I'm not super familiar with the unification of APIs behind a gateway, but I'm wondering if in this case you'd want to prefix your application routes with account and avoid rewriting the prefix on the gateway. Besides the request mapping behavior difference between annotations and functions, I don't think we can do anything about it in Spring Framework. Maybe you could ask a question on StackOverflow or create a new issue on the Spring Cloud Gateway project about that? |
This problem has stopped me now。 temporary solution is |
Now that #25279 is solved, I've checked again with the sample application. There is a major mapping difference between Spring WebFlux annotations and RouterFunctions mapping:
Debugging through sample applications show that the @poutsma @rstoyanchev this difference is the only remaining point here; I can see why RouterFunctions could be considered more explicit, and maybe nesting routes should be used instead here in applications. We're not calling out that difference anywhere in our documentation as far as I understand, maybe because I managed to reproduce this with a new test in @Test
public void pathWithContext() {
URI uri = URI.create("https://localhost/context/path");
RequestPredicate predicate = RequestPredicates.path("/p*");
MockServerHttpRequest mockRequest = MockServerHttpRequest.get(uri.toString()).contextPath("/context").build();
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), emptyList());
assertThat(predicate.test(request)).isTrue();
mockRequest = MockServerHttpRequest.head("https://example.com").build();
request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
assertThat(predicate.test(request)).isFalse();
} |
This is something that needs to be straightened out in WebFlux.fn. I will pick it up for 5.3, since it will be a breaking change for some people. |
In Spring MVC this already works as expected so we should align for consistency. The context path arguably should not be included in mappings. |
There are two services:
account-service
,gateway-server
After the
account-service
has set the 'server.forward- Headers - Strategy = Framework' property.routerFunction endpoint start 404The following interfaces are accessed through the Spring Cloud Gateway
http://localhost:8080/account/hi
is 404. The generated by RouterFunction endpointhttp://localhost:8080/account/hello
return 200 normal, through RequestMapping annotationsReproducible Example:
forward-proxy-demo.zip
The text was updated successfully, but these errors were encountered: