Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PDK): fix response body repeated when kong.response.get_raw_body() called multiple times #11424

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 28 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,31 @@ 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
local body = pdk.response.get_raw_body()
assert(body == "hello, world!\n")
local body = pdk.response.get_raw_body()
assert(body == "hello, world!\n")
local body = pdk.response.get_raw_body()
assert(body == "hello, world!\n")
}
}
--- request
GET /t
--- response_body
hello, world!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The response gets repeated if the fix is not applied: hello, world!hello, world!

--- no_error_log
[error]
Loading