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

hotfix(alf_serializer) do not include JSON body in params #766

Merged
merged 1 commit into from
Dec 3, 2015
Merged
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
47 changes: 28 additions & 19 deletions kong/plugins/mashape-analytics/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ local ALFSerializer = require "kong.plugins.log-serializers.alf"
local ngx_now = ngx.now
local ngx_log = ngx.log
local ngx_log_ERR = ngx.ERR
local string_find = string.find
local pcall = pcall

local ALF_BUFFERS = {} -- buffers per-api

Expand All @@ -33,29 +35,36 @@ end
function AnalyticsHandler:access(conf)
AnalyticsHandler.super.access(self)

-- Retrieve and keep in memory the bodies for this request
ngx.ctx.analytics = {
req_body = "",
res_body = "",
req_post_args = {}
}
local req_body = ""
local res_body = ""
local req_post_args = {}

ngx.req.read_body()

local status, res = pcall(ngx.req.get_post_args)
if not status then
if res == "requesty body in temp file not supported" then
ngx_log(ngx_log_ERR, "[mashape-analytics] cannot read request body from temporary file. Try increasing the client_body_buffer_size directive.")
else
ngx_log(ngx_log_ERR, res)
if conf.log_body then
ngx.req.read_body()
req_body = ngx.req.get_body_data()

local headers = ngx.req.get_headers()
local content_type = headers["content-type"]
if content_type and string_find(content_type:lower(), "application/x-www-form-urlencoded", nil, true) then
local status, res = pcall(ngx.req.get_post_args)
if not status then
if res == "requesty body in temp file not supported" then
ngx_log(ngx_log_ERR, "[mashape-analytics] cannot read request body from temporary file. Try increasing the client_body_buffer_size directive.")
else
ngx_log(ngx_log_ERR, res)
end
else
req_post_args = res
end
end
else
ngx.ctx.analytics.req_post_args = res
end

if conf.log_body then
ngx.ctx.analytics.req_body = ngx.req.get_body_data()
end
-- keep in memory the bodies for this request
ngx.ctx.analytics = {
req_body = req_body,
res_body = res_body,
req_post_args = req_post_args
}
end

function AnalyticsHandler:body_filter(conf)
Expand Down