GH-4025: Fix Gzip decompression logic for byte[] in ModifyResponseBodyGatewayFilterFactory #4040
+24
−10
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-4025
Description
This PR addresses an issue where ModifyResponseBodyGatewayFilterFactory fails to handle Gzipped responses correctly when the configuration is set to use byte[].class.
Root Cause:
Currently, there is an optimization logic in extractBody and writeBody methods that explicitly skips decompression/compression if the target class is byte[]:
While this might have been intended for performance, it prevents users from modifying the actual payload logic when the response is Gzipped, as the filter passes raw compressed bytes to the rewrite function. This leads to parsing errors when the user code expects decompressed data.
Changes
Removed the
if (byte[].class.isAssignableFrom(inClass))check in both extractBody and writeBody methods.Now, the filter consistently checks the Content-Encoding header and performs decompression/compression regardless of the target class type.
Verification
Added a new test case testModificationOfResponseBodyBytes in ModifyResponseBodyGatewayFilterFactoryGzipTests.
Verified that Gzipped responses are correctly decompressed, modified as strings, and recompressed even when inClass and outClass are set to byte[].