Document request header behavior of ModifyRequestBody - #4258
Open
hyungzin0309 wants to merge 1 commit into
Open
Conversation
ModifyRequestBody replaces the downstream request with a decorator whose headers are a copy taken before the RewriteFunction runs, and that decorator returns a new HttpHeaders instance on every getHeaders() call. As a result, headers set inside the RewriteFunction never reach the downstream request, and an in-place write to the HttpHeaders returned by exchange.getRequest().getHeaders() is silently discarded rather than failing with UnsupportedOperationException as it does on the underlying request. Document both constraints and show the supported alternative, mutating the request, which is what filters such as AddRequestHeader already do. Add unit tests covering the supported path and the two constraints. Each test also asserts the rewritten body reaches the chain, so the tests cannot pass if the filter stops decorating the request. Fixes spring-cloudgh-2548 Signed-off-by: hyungzin0309 <50622006+hyungzin0309@users.noreply.github.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.
ModifyRequestBodyreplaces the downstream request with a decorator whose headers are a copy taken before theRewriteFunctionruns, and that decorator returns a newHttpHeadersinstance on everygetHeaders()call.Two consequences are currently undocumented:
RewriteFunctionnever reach the downstream request — theServerWebExchangereturned byexchange.mutate()there is discarded by the filter.HttpHeadersreturned byexchange.getRequest().getHeaders()in a filter ordered afterModifyRequestBodyis silently discarded. The same write on the underlying request throwsUnsupportedOperationException, sinceAbstractServerHttpRequestwraps its headers withHttpHeaders.readOnlyHttpHeaders. Passing through this filter therefore turns a failing write into a silent one.This documents both constraints and shows the supported alternative — mutating the request, which is what filter factories such as
AddRequestHeaderalready do.Unit tests cover the supported
mutate()path and lock in the two documented constraints. Each also asserts the rewritten body reaches the chain, so they fail if the filter stops decorating the request.Verified against
main(5.0.x).Fixes gh-2548
Link: #2548