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

Resolve The matchingRequestParameterName From The Query String #13817

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

marcusdacoregio
Copy link
Contributor

Prior to this commit, the ServletRequest#getParameter method was used in order to verify if the matchingRequestParameterName was present in the request. That method has some side effects like interfering in the execution of the ServletRequest#getInputStream and ServletRequest#getReader method when the request is an HTTP POST (if those methods are invoked after getParameter, or vice-versa, the content won't be available). This commit makes that we only use the query string to check for the parameter, avoiding draining the request's input stream.

Closes gh-13731

@marcusdacoregio marcusdacoregio added in: web An issue in web modules (web, webmvc) type: bug A general bug labels Sep 14, 2023
@marcusdacoregio marcusdacoregio added this to the 6.0.7 milestone Sep 14, 2023
@marcusdacoregio marcusdacoregio self-assigned this Sep 14, 2023
@@ -100,8 +102,9 @@ public void removeRequest(HttpServletRequest currentRequest, HttpServletResponse

@Override
public HttpServletRequest getMatchingRequest(HttpServletRequest request, HttpServletResponse response) {
if (this.matchingRequestParameterName != null
&& request.getParameter(this.matchingRequestParameterName) == null) {
MultiValueMap<String, String> queryParams = UriComponentsBuilder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works, it is not optimal. If this.matchingRequestParameterName is null, then the parsing of the query parameters should not be done because it is unnecessary work.

Prior to this commit, the ServletRequest#getParameter method was used in order to verify if the matchingRequestParameterName was present in the request. That method has some side effects like interfering in the execution of the ServletRequest#getInputStream and ServletRequest#getReader method when the request is an HTTP POST (if those methods are invoked after getParameter, or vice-versa, the content won't be available). This commit makes that we only use the query string to check for the parameter, avoiding draining the request's input stream.

Closes spring-projectsgh-13731
@marcusdacoregio marcusdacoregio merged commit 18e8836 into spring-projects:6.0.x Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web An issue in web modules (web, webmvc) type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants