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(admin) avoid Lapis handler when handler doesn't exit explicitly #4077

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion kong/api/endpoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ local function post_collection_endpoint(schema, foreign_schema, foreign_field_na
if post_process then
entity, _, err_t = post_process(entity)
if err_t then
handle_error(err_t)
return handle_error(err_t)
end
end

Expand Down
7 changes: 6 additions & 1 deletion kong/api/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ local function parse_params(fn)

self.params = api_helpers.normalize_nested_params(self.params)

return fn(self, ...)
local res = fn(self, ...)
if res == nil and ngx.status >= 200 then
return ngx.exit(0)
end

return res
end)
end

Expand Down
46 changes: 46 additions & 0 deletions spec/02-integration/04-admin_api/25-plugin-endpoints.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
local helpers = require "spec.helpers"


for _, strategy in helpers.each_strategy() do

describe("Admin API endpoints added via plugins #" .. strategy, function()
local client

setup(function()
local bp = helpers.get_db_utils(strategy, {
"plugins",
}, {
"admin-api-method"
})

bp.plugins:insert({
name = "admin-api-method",
})

assert(helpers.start_kong({
database = strategy,
nginx_conf = "spec/fixtures/custom_nginx.template",
plugins = "admin-api-method",
}))
client = helpers.admin_client()
end)

teardown(function()
if client then
client:close()
end
helpers.stop_kong()
end)

it("a method without an explicit exit does not add Lapis output", function()
local res = assert(client:send {
method = "GET",
path = "/method_without_exit",
headers = { ["Content-Type"] = "application/json" }
})
local body = assert.res_status(201 , res)
assert.same("hello", body)
end)
end)

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
return {
["/method_without_exit"] = {
GET = function()
kong.response.set_status(201)
kong.response.set_header("x-foo", "bar")
ngx.print("hello")
end,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- a plugin fixture to test a method on the admin api
local BasePlugin = require "kong.plugins.base_plugin"


local AdminApiMethod = BasePlugin:extend()


AdminApiMethod.PRIORITY = 1000


function AdminApiMethod:new()
AdminApiMethod.super.new(self, "admin-api-method")
end


return AdminApiMethod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return {
fields = {
foo = { type = "string" }
}
}