feat(response): add support for gzip decompression in response.get_bo… #14801
+15
−6
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.
Summary
This PR implements the missing
decompressedparameter forkong.service.response.get_body()that was documented in the PDK reference but never actually implemented.Problem:
The
kong.service.response.get_body()function has been documented with an optionaldecompressedparameter, but the parameter was never implemented. This causes the function to returnnilwhen trying to parse compressed response bodies (e.g., gzip-compressed JSON) because it attempts to parse the compressed data directly, which fails.Example of current broken behavior:
Content-Type: application/jsonandContent-Encoding: gzipkong.service.response.get_body()attempts to JSON-decode the gzipped bytesnilwith error "invalid json body"Solution:
decompressedparameter inkong/pdk/service/response.luadecompressed=true, the function now:Content-Encodingheadergzip, decompresses the body usingkong.tools.gzip.inflate_gzip()Implementation Details:
kong.tools.gzipmodule for gzip decompressiondecompressedis not provided orfalse, behavior is unchanged (still returnsnilfor compressed bodies)Testing Clarification Needed
The contributing guidelines recommend Busted tests, but
t/01-pdk/07-service-response/05-get_body.texists with only a TODO placeholder. Additionally, there's no clear pattern for testingkong.service.response.*functions that require actual upstream responses.Need guidance on:
t/01-pdk/07-service-response/05-get_body.t(Nginx test),spec/(Busted), or both?Once I understand the testing approach, I'll add tests covering:
Checklist
changelog/unreleased/kongorskip-changeloglabel added on PR if changelog is unnecessary. README.md