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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

raccoonback
Copy link

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

Successfully merging this pull request may close these issues.

3 participants