spring-cloud / spring-cloud/spring-cloud-gateway

RewriteLocationResponseHeader via app-yaml as per documentation does not work

Open
#3,729 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug in: server-webmvc
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the application.yml route definition and the RewriteLocationResponseHeader filter in the linked sample application. Reproduce the startup failure, then trace how the filter arguments are parsed when the final values are empty. Done means the documented configuration starts successfully and preserves the filter's default values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.