Guard header copy against committed response in NettyRoutingFilter - #4272
Open
adityaanikam wants to merge 1 commit into
Open
Guard header copy against committed response in NettyRoutingFilter#4272adityaanikam wants to merge 1 commit into
adityaanikam wants to merge 1 commit into
Conversation
NettyRoutingFilter unconditionally called response.getHeaders() .remove(...) and .addAll(...) when copying the filtered response headers onto the client response. Once a response is committed, AbstractServerHttpResponse#getHeaders() returns a cached ReadOnlyHttpHeaders wrapper, and mutating it throws UnsupportedOperationException. Guard the header-copy step with response.isCommitted(), matching the same check already used elsewhere in this codebase (see BaseWebClientTests#modifyResponseFilter). Headers can no longer reach the client past that point regardless, so skipping is safe. Fixes spring-cloudgh-4270 Signed-off-by: adityaanikam <adityanikam9502@gmail.com>
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-4270
Problem
NettyRoutingFiltercopies filtered response headers back onto theclient response near the end of
filter():If the response has already been committed elsewhere in the filter
chain before routing completes,
AbstractServerHttpResponse#getHeaders()returns a cached
ReadOnlyHttpHeaderswrapper instead of the mutableheaders map. Calling
remove(...)oraddAll(...)on that wrapperthrows
UnsupportedOperationException, which surfaces as an errorsignal on the filter chain instead of the response completing
normally.
Fix
Guard the header-copy step with
response.isCommitted(). Once aresponse is committed, headers can no longer reach the client
regardless, so skipping the copy is safe and matches an existing
precedent already in the test codebase
(
BaseWebClientTests#modifyResponseFilter, which uses the sameisCommitted()check before touching response headers).Testing
NettyRoutingFilterTests#routingAfterResponseAlreadyCommittedDoesNotThrow,which pre-commits a
MockServerWebExchangeand assertsnettyRoutingFilter.filter(...)completes normally instead oferroring.
NettyRoutingFilterTestssuite passes.the new test) reproduces the exact reported
UnsupportedOperationExceptionatReadOnlyHttpHeaders.remove(ReadOnlyHttpHeaders.java:166), matchingthe original issue's stack trace. Restoring the fix passes cleanly.