Repository navigation
Conversation
HttpHeaders#getContentType() validates the charset parameter and throws InvalidMediaTypeException for values such as "x-user-defined" that clients may send. Parse only the type and subtype when deciding whether a response should be streamed, so the response body can still be proxied. Fixes spring-cloudgh-3695 Signed-off-by: hebulin <hebulin@qq.com>
This branch has not been deployed
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.
Summary
Fixes #3695 by allowing Spring Cloud Gateway Server WebMVC to proxy responses whose
Content-Typecontains a non-standard charset such asx-user-defined.Root Cause
AbstractProxyExchange.copyResponseBodyandisStreamingResponsecallHttpHeaders.getContentType(). In Spring Framework, that method parses the charset parameter and throwsInvalidMediaTypeExceptionfor unsupported values. Clients may legitimately sendContent-Type: text/plain; charset=x-user-definedwhen downloading binary data, so the gateway fails with a 500 before the response body is written.Fix
Content-Typeheader and parse only its type and subtype, ignoring parameters.null(non-streaming copy) when the type/subtype itself is invalid.isStreamingResponse, which is used while closing a response after a copy error.Before-After
text/plain; charset=x-user-definedInvalidMediaTypeExceptiontext/event-stream; charset=x-user-definedInvalidMediaTypeExceptionBackward Compatibility
Valid content types behave as before, because parameters were already ignored by
equalsTypeAndSubtype. Missing or malformed types are still treated as non-streaming. Response headers are forwarded unchanged.Closes #3695