Skip to content

Commit

Permalink
fix(PDK): fix response body repeated when kong.response.get_raw_body(…
Browse files Browse the repository at this point in the history
…) called multiple times (#11424)
  • Loading branch information
vm-001 authored Aug 21, 2023
1 parent 95cecef commit 48a2de2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG/unreleased/kong/11424.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
message: Fix response body gets repeated when `kong.response.get_raw_body()` is called multiple times in a request lifecycle.
type: bugfix
scope: PDK
prs:
- 11424
jiras:
- "FTI-5296"
1 change: 1 addition & 0 deletions kong/pdk/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ local function new(self, major_version)
end

arg[1] = body_buffer
ngx.ctx.KONG_BODY_BUFFER = nil
return body_buffer
end

Expand Down
34 changes: 34 additions & 0 deletions t/01-pdk/08-response/14-get_raw_body.t
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,37 @@ Enhanced by Body Filter
Called 3 times
--- no_error_log
[error]
=== TEST 3: response.get_raw_body() calls multiple times
--- http_config eval: $t::Util::HttpConfig
--- config
location = /t {
content_by_lua_block {
ngx.print("hello, world!\n")
}
body_filter_by_lua_block {
local PDK = require "kong.pdk"
local pdk = PDK.new()
-- call pdk.response.get_raw_body() multiple times
ngx.ctx.called = (ngx.ctx.called or 0) + 1
for i = 1, 3 do
ngx.ctx.called2 = (ngx.ctx.called2 or 0) + 1
local body = pdk.response.get_raw_body()
if body then
assert("hello, world!\n" == body)
end
end
}
log_by_lua_block {
assert(ngx.ctx.called == 2)
assert(ngx.ctx.called2 == 6)
}
}
--- request
GET /t
--- response_body
hello, world!
--- no_error_log
[error]

1 comment on commit 48a2de2

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:48a2de21ee765f84742b382b9a043d16da4d7348
Artifacts available https://github.com/Kong/kong/actions/runs/5922703198

Please sign in to comment.