Support to redirect with initial request path to the redirected request in RedirectTo filter.
Problem: The current RedirectTo filter, takes in the following config:
spring:
cloud:
gateway:
routes:
- id: prefixpath_route
uri: https://example.org
filters:
- RedirectTo=302, https://acme.org, true
With current approach when redirection takes place it sets the response status to '302' and sets the 'Location' header to the provided URI, and also provides an option to include query param from the initial request. But this implementation drops the request path of the original request.
Ex:
Initial Request: GET http://localhost:8080/target/get?query1=value1
Redirected Request: GET https://acme.org?query1=value1
With the current implementation the initial request path is /target/get is dropped.
Proposed Solution:
Provide an option similar to includeRequestParams to indicate whether the initial request path should be included on the url. The parameter is treated as false when not set to preserve backwards compatibility.
This is similar to what Apache mod_alias Redirect directive does, so I am thinking of similar solution, which supports adding request path to the redirected request. https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect
Hi @spencergibb, @ryanjbaxter
I've submitted a PR (#4372) addressing this enhancement.
The implementation introduces an optional includeRequestPath parameter to the RedirectTo filter, allowing the original request path to be appended to the destination URL. It also supports forwarding query parameters alongside the request path while preserving the existing behavior by default.
I've added tests covering the default behavior, path inclusion, query parameter forwarding, and trailing slash handling.
Feedback and suggestions are welcome. Thank you!