Skip to content

fix(response-transformer): guard body_filter against unbuffered chunks - #14968

Open
Adityaj0 wants to merge 1 commit into
Kong:masterfrom
Adityaj0:fix/response-transformer-nil-body-check
Open

fix(response-transformer): guard body_filter against unbuffered chunks#14968
Adityaj0 wants to merge 1 commit into
Kong:masterfrom
Adityaj0:fix/response-transformer-nil-body-check

Conversation

@Adityaj0

@Adityaj0 Adityaj0 commented Aug 2, 2026

Copy link
Copy Markdown

Summary

Fixes #14967.

kong.response.get_raw_body() returns nil on every body_filter call 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'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 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 standard if not body then return end guard after kong.response.get_raw_body(), mirroring the pattern already used by proxy-cache and documented in the PDK function's own usage example.

Test plan

  • The existing spec/03-plugins/15-response-transformer/05-big_response_body_spec.lua already 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 -p syntax-checked the changed file.
  • CI (I was not able to run the full busted/OpenResty integration suite in my local environment — please let me know if a log-assertion addition to the existing big-response-body spec would be welcome and I'll add one).

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.
@CLAassistant

CLAassistant commented Aug 2, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

response-transformer logs spurious "body transform failed" warnings on large/chunked JSON responses

2 participants