Skip to content

ForwardedHeaderFilter should allow prepend / replace depending on configuration #27739

Closed
@antechrestos

Description

@antechrestos

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 to my-local-context-path and seen by first application as app-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 with X-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 in 404 error as the correct url should have been http://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 to REPLACEMENT by default

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions