Skip to content

Allow optional RewriteLocationResponseHeader arguments in server-webmvc - #4315

Open
sharanggupta wants to merge 1 commit into
spring-cloud:mainfrom
sharanggupta:gh-3729-rewrite-location-response-header-shortcut
Open

sharanggupta wants to merge 1 commit into
spring-cloud:mainfrom
sharanggupta:gh-3729-rewrite-location-response-header-shortcut

Conversation

@sharanggupta

@sharanggupta sharanggupta commented Oct 6, 2026 •

Copy link
Copy Markdown

Fixes gh-3729

Configuring RewriteLocationResponseHeader from properties with any argument omitted — including the form documented on the filter's page, RewriteLocationResponseHeader=AS_IN_REQUEST, Location, ,, the bare RewriteLocationResponseHeader, or name/args with a subset of the parameters — failed at startup with Unable to find operation ... rewriteLocationResponseHeader with args {_genkey_0=AS_IN_REQUEST, _genkey_1=Location}.

The only shortcut for the filter took all four arguments as Strings, and operation matching requires the argument count to equal the parameter count; empty trailing shortcut tokens are dropped during tokenization, so nothing matched.

This exposes the filter through a @Shortcut/@Configurable method bound to RewriteLocationResponseHeaderConfig, the same way Retry and CircuitBreaker accept optional arguments. Positional shortcuts of any length, the no-argument form and arbitrary named subsets now resolve; the existing four-String method is unchanged and still handles the full positional form. The docs page is aligned with the real parameter names (stripVersion, protocolsRegex) and shows the named-argument form.

A blank hostValue, such as an empty hostValue: named argument (the case raised in the issue), now counts as not set and falls back to the request Host header instead of replacing the host with an empty string.

Tests: RewriteLocationResponseHeaderPropertiesTests (no Testcontainers needed) covers trailing-empty shortcut, no-arg shortcut, named subset, blank hostValue, and the full four-argument form. ./mvnw -pl spring-cloud-gateway-server-webmvc verify is green locally for the non-Docker tests, javaformat and checkstyle.

Note: #3886 addresses the same issue via 1–3 String overloads; this takes the config-binding approach instead so that named subsets such as stripVersion + protocolsRegex also work and AS_IN_REQUEST, Location, , https? is not misread as a host value. Happy to defer if the maintainers prefer that PR.

Configuring the filter from properties with any argument omitted, e.g.
the documented `RewriteLocationResponseHeader=AS_IN_REQUEST, Location, ,`
or the bare `RewriteLocationResponseHeader`, failed at startup with
"Unable to find operation ... rewriteLocationResponseHeader". The only
shortcut method took all four arguments as Strings, and operation
matching requires the argument count to equal the parameter count, so
trailing empty shortcut tokens (dropped during tokenization) and
named-argument subsets had nothing to bind to.

Expose the filter through a @configurable shortcut that binds the
arguments onto RewriteLocationResponseHeaderConfig, the same way the
Retry and CircuitBreaker filters accept optional arguments. Positional
shortcuts of any length, the no-argument form and arbitrary named
subsets now resolve, while the four-String method is kept as is.

A blank hostValue, such as an empty `hostValue:` named argument, now
counts as not set and falls back to the request Host header instead of
replacing the host with an empty string. Also align the docs with the
real parameter names.

Fixes spring-cloudgh-3729

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RewriteLocationResponseHeader via app-yaml as per documentation does not work

2 participants