From acf149812731fd91bf98a271d45f4e56a23c9e07 Mon Sep 17 00:00:00 2001 From: "Satish K. Pagare" Date: Wed, 30 Aug 2017 13:17:45 +0530 Subject: [PATCH] Added APICAST_PAYLOAD_BASE64 environment variable to switch base64 encoding of the request-response payload. By default it gets set to 'true'. If the payload needs to be logged in plain-text readbale format assuming its in simple XML/JSON/Text format, then the flag needs to be set to 'false'. --- verbose.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/verbose.lua b/verbose.lua index eae9359..70355e2 100644 --- a/verbose.lua +++ b/verbose.lua @@ -27,6 +27,7 @@ function _M:init() host = os.getenv('SYSLOG_HOST') port = os.getenv('SYSLOG_PORT') proto = os.getenv('SYSLOG_PROTOCOL') or 'tcp' + base64_flag = os.getenv('APICAST_PAYLOAD_BASE64') or 'true' flush_limit = os.getenv('SYSLOG_FLUSH_LIMIT') or '0' periodic_flush = os.getenv('SYSLOG_PERIODIC_FLUSH') or '5' drop_limit = os.getenv('SYSLOG_DROP_LIMIT') or '1048576' @@ -103,12 +104,21 @@ function _M.body_filter() -- Gather information of the request local request = {} if ngx.var.request_body then - request["body"] = ngx.encode_base64(ngx.var.request_body) + if (base64_flag == 'true') then + request["body"] = ngx.encode_base64(ngx.var.request_body) + else + request["body"] = ngx.var.request_body + end end request["headers"] = ngx.req.get_headers() request["start_time"] = ngx.req.start_time() request["http_version"] = ngx.req.http_version() - request["raw"] = ngx.encode_base64(ngx.req.raw_header()) + if (base64_flag == 'true') then + request["raw"] = ngx.encode_base64(ngx.req.raw_header()) + else + request["raw"] = ngx.req.raw_header() + end + request["method"] = ngx.req.get_method() request["uri_args"] = ngx.req.get_uri_args() request["request_id"] = ngx.var.request_id @@ -117,7 +127,11 @@ function _M.body_filter() -- Gather information of the response local response = {} if ngx.ctx.buffered then - response["body"] = ngx.encode_base64(ngx.ctx.buffered) + if (base64_flag == 'true') then + response["body"] = ngx.encode_base64(ngx.ctx.buffered) + else + response["body"] = ngx.ctx.buffered + end end response["headers"] = ngx.resp.get_headers() response["status"] = ngx.status