Description
After seeing discussion put in #18949,
Let's see the following case
Spring boot BOM version 2.5.6
Spring cloud 2020.0.4
- spring gateway with default locator configuration exposed on http://my-gateway.url
- a spring boot application with a
server.servlet.context-path
set tomy-local-context-path
and seen by first application asapp-ui
in its discovery client
The second application uses thymeleaf @{/js/script.js}
in the template returned by the handler of /some-mvc-controller
When accessing on http://my-gateway.url/app-ui/my-local-context-path/some-mvc-controller
- spring cloud gateway calls app-ui application on
/my-local-context-path/some-mvc-controller
withX-Forwarded-Prefix
set to/app-ui
ForwardedHeaderFilter
replaces http servlet request context path to/app-ui
, request uri to/app-ui/some-mvc-controller
- Thymeleaf resolves js url to
http://my-gateway.url/app-ui/js/script.js
that ends in404
error as the correct url should have beenhttp://my-gateway.url/app-ui/my-local-context-path/js/script.js
Unless I missed something, I think that it is sad that, using all default behaviour of spring tools (but context-path) is not possible.
I would like to provide a way to let application choose between a policy of REPLACEMENT
or PREPEND
. If none, something like setting inner classes of ForwardedHeaderFilter
as protected
instead of private
in order to let application easily implement its own policy.
Before going directly to a pull request, I prefer discussing whether you're ok with that and which would be the prefered solution
- moving inner classes to
protected
without any other change - allowing to switch between replacement and prepend based on
server.framework-forward-header-policy
valued toREPLACEMENT
by default