fix(response-transformer): guard body_filter against unbuffered chunks - #14968
Open
Adityaj0 wants to merge 1 commit into
Open
fix(response-transformer): guard body_filter against unbuffered chunks#14968Adityaj0 wants to merge 1 commit into
Adityaj0 wants to merge 1 commit into
Conversation
kong.response.get_raw_body() returns nil on every body_filter call that isn't the last chunk of the response body (it buffers internally and only returns the full body once eof is reached) -- documented on the function itself, and already handled correctly by other first-party plugins consuming it (e.g. proxy-cache). response-transformer's body_filter called transform_json_body(conf, body) unconditionally, so on every intermediate chunk of any JSON response that doesn't fit in a single buffer, it tried to JSON-decode nil, got a "failed parsing json body" error, and logged a warn-level "body transform failed" line -- once per intermediate chunk, for completely normal traffic. The final chunk was still transformed correctly, so this only produced log noise, but at volume it can flood logs and mislead operators debugging real transform failures.
1 task
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.
Summary
Fixes #14967.
kong.response.get_raw_body()returnsnilon everybody_filtercall that isn't the last chunk of the response body — documented on the function itself, and already handled correctly by other first-party plugins consuming it (e.g.proxy-cache).response-transformer'sbody_filtercalledtransform_json_body(conf, body)unconditionally, so on every intermediate chunk of any JSON response that doesn't fit in a single buffer, it tried to JSON-decodenil, got a "failed parsing json body" error, and logged awarn-level "body transform failed" line — once per intermediate chunk, for completely normal traffic. The final chunk was still transformed correctly, so this is a log-noise-only issue, but at volume it can flood logs and mislead operators debugging real transform failures.Changes
kong/plugins/response-transformer/handler.lua: added the standardif not body then return endguard afterkong.response.get_raw_body(), mirroring the pattern already used byproxy-cacheand documented in the PDK function's own usage example.Test plan
spec/03-plugins/15-response-transformer/05-big_response_body_spec.luaalready exercises the multi-chunk scenario this bug occurs in end-to-end (1MB JSON body) and should continue to pass unchanged; asserting on the absence of the spurious warning log would require extending that integration spec with error-log inspection, which I wasn't able to verify without a local test-execution environment (see below).luac -psyntax-checked the changed file.