GH-11235: Fix form data read in MultipartAware converter - #11240
Closed
kdelay wants to merge 1 commit into
Closed
Conversation
Fixes: spring-projectsgh-11235 `MultipartAwareFormHttpMessageConverter` used to delegate to an `AllEncompassingFormHttpMessageConverter`, which reads and writes both `application/x-www-form-urlencoded` and `multipart/form-data`. It now delegates to a `MultipartHttpMessageConverter`, which handles only `multipart/form-data`. Therefore a form-urlencoded request body fails with `No multipart boundary found in Content-Type`, and this is what disabled `HttpDslTests.testHttpProxyFlow()`: the proxied `POST` to the internal gateway carries a form-urlencoded body. * delegate non-multipart reads and writes to a `FormHttpMessageConverter` and keep the `MultipartHttpMessageConverter` for multipart * report the media types of both delegates from `getSupportedMediaTypes()` and accept both in `canWrite()` * read against a `MultiValueMap` target type: the inbound endpoint falls back to `byte[]` when no request payload type is configured, and `FormHttpMessageConverter` returns a single-value `Map` for that type * add `MultipartAwareFormHttpMessageConverterTests` and re-enable `HttpDslTests.testHttpProxyFlow()` Signed-off-by: kdelay <kdelay20@gmail.com>
Member
|
Duplicate of: #11236? give you AI a hint to not fix if it is present on the issue already . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: gh-11235
HttpDslTests.testHttpProxyFlow()fails because of a regression inMultipartAwareFormHttpMessageConverter, not because of the reflectiveRestTestClientfield path.The converter used to delegate to an
AllEncompassingFormHttpMessageConverter, which reads and writes bothapplication/x-www-form-urlencodedandmultipart/form-data. It now delegates to aMultipartHttpMessageConverter, which handles onlymultipart/form-data, so any form-urlencoded request body fails with:The proxied request in that test is a
POSTto/service/internalwith a form-urlencoded body, which is why it surfaced there. Any HTTP inbound gateway or channel adapter receiving a form post is affected, sinceHttpRequestHandlingEndpointSupportregisters this converter first.Changes:
FormHttpMessageConverter; theMultipartHttpMessageConverteris kept for multipart, selected by the sameisMultipart()rule the old delegate used (amultipartcontent type, or a non-Stringvalue in the map)getSupportedMediaTypes()reports the media types of both delegates andcanWrite()accepts both; with the multipart-only delegate,application/x-www-form-urlencodedhad disappeared from bothMultiValueMaptarget type.HttpRequestHandlingEndpointSupport.extractRequestBody()falls back tobyte[]when no request payload type is configured, andFormHttpMessageConverter.read()returns a single-valueMapfor a non-MultiValueMaptype, which then fails the cast in this converter.setCharset()now applies to both delegatesVerification:
MultipartAwareFormHttpMessageConverterTestsis new; with only the test files applied and the converter reverted, all four of its tests fail, as doestestHttpProxyFlow()./gradlew :spring-integration-http:test— 235 tests, 0 failures./gradlew :spring-integration-webflux:test— 35 tests, 0 failurescheckstyleMainandcheckstyleTestpass for thehttpmodule