Skip to content
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

Support rewriting request parameters in mvc #3669

Merged

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 <[email protected]>
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants