Skip to content

RewriteLocationResponseHeader via app-yaml as per documentation does not work #3729

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

Open
kontza opened this issue Mar 19, 2025 · 3 comments
Open

Comments

@kontza
Copy link

kontza commented Mar 19, 2025

Describe the bug
I'm trying to add RewriteLocationResponseHeader filter to my application.yml route definition. I'm using the format given in the documentation:

filters:
  - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, ,

However, the app startup fails with:

Caused by: java.lang.IllegalArgumentException: 
  Unable to find operation interface org.springframework.web.servlet.function.HandlerFilterFunction for 
  rewriteLocationResponseHeader with args {_genkey_0=AS_IN_REQUEST, _genkey_1=Location}

I cannot, for the life of me, figure out how to tell it to use default values for the last two parameters. I've tried:

  • RewriteLocationResponseHeader=AS_IN_REQUEST, Location, '', '': this ended up creating a string containing ''.
  • RewriteLocationResponseHeader=AS_IN_REQUEST, Location, "", "": this ended up creating a string containing "".
  • RewriteLocationResponseHeader=AS_IN_REQUEST, Location, {}, {}: this ended up creating a string containing {}.

It seems as the code handling the extraction of parameters to the filter does not correctly handle empty strings. Or something along those lines.

The question is: How am I supposed to specify empty strings in app yaml to RewriteLocationResponseHeader?

Sample
I've forked the excellent demo by eyal33 which can be used to demo it. You don't need to setup any Docker stuff, just try to run the app, and the RewriteLocationResponseHeader line will take care of application startup failing.

The sample application: https://github.com/kontza/spring-cloud-gateway-mvc-demo

@spencergibb
Copy link
Member

spencergibb commented Mar 19, 2025

I'm not sure if there is a shortcut bug, or just bad documentation. Did you try it without the last two arguments? (my guess is you get the same error)

filters:
  - RewriteLocationResponseHeader=AS_IN_REQUEST, Location

Don't use the shortcut as a workaround

filters:
  - name: RewriteLocationResponseHeader
    args:
      stripVersion: AS_IN_REQUEST
      locationHeaderName: Location

@kontza
Copy link
Author

kontza commented Mar 19, 2025

  1. Without the last two arguments I get the same error.
  2. I had no idea you could define a filter like that, with name, and args! However, that fails, too. It started working after making it look like this:
    filters:
    - name: RewriteLocationResponseHeader
      args:
        stripVersion: AS_IN_REQUEST
        locationHeaderName: Location
        hostValue:
        protocolsRegex: https?
  3. I don't know if an empty string to hostValue is a good idea as RewriteLocationResponseHeaderFilterFunctions#rewriteLocationResponseHeader checks for a null value and an empty field in YAML will be converted, to my understanding, to an empty string. Please see

@spencergibb
Copy link
Member

spencergibb commented Mar 19, 2025

Yeah, I ran into the same thing as I was investigating. This is definitely a bug worth fixing. Glad there is a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants