KEMBAR78
Support rewriting request parameters in mvc by raccoonback · Pull Request #3669 · spring-cloud/spring-cloud-gateway · GitHub
Skip to content

Conversation

@raccoonback
Copy link
Contributor

Pull Request Description

Hello,

Currently, Spring Cloud Gateway provides a feature to replace HTTP Request Query Parameters through RewriteRequestParameterGatewayFilterFactory.
This Pull Request introduces the same functionality in spring-cloud-gateway-server-mvc, enabling developers to easily modify or replace Query Parameters in the MVC environment.

Motivation

the rewriteRequestParameter function provides a simple and concise way to modify Query Parameters, as shown below:

// Request URI: http://localhost/path?foo=bar

-> BeforeFilterFunctions.rewriteRequestParameter("foo", "replacement").apply(request);

// ServerRequest URI result: http://localhost/path?foo=replacement

This approach consolidates the process of replacing a Query Parameter into a single method call, improving code clarity and reducing boilerplate.

Current Limitation

Currently, achieving the same result in the MVC environment requires two separate operations: removing and then adding the Query Parameter:

// Request URI: http://localhost/path?foo=bar

-> ServerRequest result = BeforeFilterFunctions.removeRequestParameter("foo")
                .andThen(BeforeFilterFunctions.addRequestParameter("foo", "replacement"))
                .apply(request);

// ServerRequest URI result: http://localhost/path?foo=replacement

Proposed Solution

By introducing the rewriteRequestParameter method in MVC, developers can seamlessly handle both the removal and addition of Query Parameters in a single operation. This enhancement will:

  • Simplify code by reducing multi-step operations to a single method call.
  • Improve maintainability and readability for Query Parameter modification logic.

I look forward to your feedback and suggestions on this improvement.
Thanks!

Introduced a method to modify or replace request parameters during request processing, providing greater flexibility for parameter handling in routing.

Signed-off-by: raccoonback <kosb15@naver.com>
@raccoonback raccoonback force-pushed the rewrite-query-parameter-in-mvc branch from 3ecd882 to ae14508 Compare January 15, 2025 16:07
@spencergibb spencergibb added this to the 4.3.0-M2 milestone Jan 31, 2025
@spencergibb spencergibb merged commit f76397d into spring-cloud:main Jan 31, 2025
2 of 3 checks passed
Been24 pushed a commit to Been24/spring-cloud-gateway that referenced this pull request Mar 14, 2025
Introduced a method to modify or replace request parameters during request processing, providing greater flexibility for parameter handling in routing.

Signed-off-by: raccoonback <kosb15@naver.com>
Signed-off-by: ubest <zhangfeng@sipg.com.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants