Skip to content

Treat empty decompressed response bodies as absent in ModifyResponseBody - #4319

Open
sharanggupta wants to merge 1 commit into
spring-cloud:mainfrom
sharanggupta:gh-4318-modify-response-body-empty-chunked
Open

sharanggupta wants to merge 1 commit into
spring-cloud:mainfrom
sharanggupta:gh-4318-modify-response-body-empty-chunked

Conversation

@sharanggupta

Copy link
Copy Markdown

Fixes gh-4318

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). 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 switchIfEmpty path invokes the RewriteFunction with null, 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): emptyBodyAfterDecompressionIsPassedToRewriteFunctionAsNull reproduces the report (it fails with "No content to map due to end-of-input" without the change), emptyBodyPublisherIsPassedToRewriteFunctionAsNull guards the empty-publisher path, and validJsonBodyIsDecodedBeforeRewriting and malformedNonEmptyJsonBodyStillFailsToDecode guard 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.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModifyResponseBodyGatewayFilterFactory fails on empty chunked 2xx responses after upgrade to Spring Cloud Gateway 5

2 participants