Repository navigation
Treat empty decompressed response bodies as absent in ModifyResponseBody - #4319
Open
sharanggupta wants to merge 1 commit into
Open
sharanggupta wants to merge 1 commit into
sharanggupta wants to merge 1 commit into
Conversation
ModifyResponseBodyGatewayFilterFactory passed a zero-length buffer to the configured decoder when a compressed response was empty once decompressed, for example a gzip encoded empty body sent with chunked transfer encoding. Decoders such as Jackson reject zero bytes, so the gateway answered a successful downstream response with a 500. Skip decoding in that case so that the RewriteFunction is invoked with null, as it already is for a response that carries no body. Fixes spring-cloudgh-4318 Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
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.
Fixes gh-4318
ModifyResponseBodyGatewayFilterFactorypassed a zero-length buffer to the configured decoder when a compressed response was empty once decompressed (for example a gzip encoded empty body sent with chunked transfer encoding). Jackson rejects zero bytes ("No content to map due to end-of-input"), so a 2xx downstream response turned into a 500.The decoded bytes are now filtered when empty, so the existing
switchIfEmptypath invokes theRewriteFunctionwithnull, the same as for a response without a body. Non-empty bodies, including malformed JSON, behave as before. An uncompressed empty chunked response already took the empty-publisher path and worked in a raw-socket probe, so the fix is limited to the compressed branch.Tests (
ModifyResponseBodyGatewayFilterFactoryUnitTests, no Docker):emptyBodyAfterDecompressionIsPassedToRewriteFunctionAsNullreproduces the report (it fails with "No content to map due to end-of-input" without the change),emptyBodyPublisherIsPassedToRewriteFunctionAsNullguards the empty-publisher path, andvalidJsonBodyIsDecodedBeforeRewritingandmalformedNonEmptyJsonBodyStillFailsToDecodeguard the cases that must not change../mvnw -pl spring-cloud-gateway-server-webflux validate(javaformat and checkstyle) passes.The reporter of the issue confirmed this analysis in the issue thread and offered to test the fix.