Do not propagate forwarded body Content-Type to the real response - #4282
Open
scottfrederick wants to merge 1 commit into
Open
Do not propagate forwarded body Content-Type to the real response#4282scottfrederick wants to merge 1 commit into
scottfrederick wants to merge 1 commit into
Conversation
Suppress Content-Type propagation on the ProxyExchange wrapper to prevent HTTP 500 errors when the content type is not provided. Signed-off-by: Scott Frederick <scottyfred@gmail.com>
Member
|
Only proxyexchange webmvc? |
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.
ProxyExchange.forward()returns HTTP 500 for any request whose client sends noAcceptheader on recent Tomcat versions.Cause
ProxyExchange.forward()renders the request body through aHttpServletResponseWrapperthat captures the rendered bytes so they can be replayed as the forwarded request's input.The wrapper does not intercept
Content-Type, so it delegates to the real response. The type written there is the one negotiated for the outer request. A body rendered asStringfor a client that sent noAcceptheader negotiatestext/plain. That value stays on the real response when the forward is dispatched.Historically this was harmless.
Response.getHeader("Content-Type")returnednull, so the forwarded handler re-negotiated and picked its own type. Tomcat changedgetHeaderto return the content type (https://bz.apache.org/bugzilla/show_bug.cgi?id=69967, released in 9.0.116, 10.1.53 and 11.0.19). The forwarded handler now seesContent-Typeas already set, skips re-negotiation, finds notext/plainconverter for its return type, and fails with HTTP 500.Why existing tests did not catch this
postForwardBodyandpostForwardForgetBodyare the two tests that exercise this path, and both sendAccept: applicati on/json, which negotiates a type the forwarded handler can also produce, so the propagatedContent-Typeis one the handler can satisfy.