Skip to content

Commit

Permalink
Galileo plugin: base64-encode the bodies of req/res
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrondin committed Nov 25, 2015
1 parent bf8465f commit 873d828
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
9 changes: 7 additions & 2 deletions kong/plugins/log-serializers/alf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

local stringy = require "stringy"

local ngx_encode_base64 = ngx.encode_base64

local EMPTY_ARRAY_PLACEHOLDER = "__empty_array_placeholder__"

-- Transform a key/value lua table into an array of elements with `name`, `value`.
Expand Down Expand Up @@ -67,6 +69,9 @@ function _M.serialize_entry(ngx)
local alf_res_body = analytics_data.res_body or ""
local alf_req_post_args = analytics_data.req_post_args or {}

local alf_base64_req_body = ngx_encode_base64(alf_req_body)
local alf_base64_res_body = ngx_encode_base64(alf_res_body)

-- timers
local proxy_started_at, proxy_ended_at = ngx.ctx.proxy_started_at, ngx.ctx.proxy_ended_at

Expand Down Expand Up @@ -130,7 +135,7 @@ function _M.serialize_entry(ngx)
postData = {
mimeType = alf_req_mimeType,
params = dic_to_array(alf_req_post_args),
text = alf_req_body
text = alf_base64_req_body
}
},
response = {
Expand All @@ -145,7 +150,7 @@ function _M.serialize_entry(ngx)
content = {
size = tonumber(ngx.var.body_bytes_sent),
mimeType = alf_res_mimeType,
text = alf_res_body
text = alf_base64_res_body
}
},
cache = {},
Expand Down
3 changes: 3 additions & 0 deletions kong/tools/ngx_stub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ _G.ngx = {
return res_str, sub_made
end
},
encode_base64 = function(str)
return string.format("base64_%s", str)
end,
-- Builds a querystring from a table, separated by `&`
-- @param `tab` The key/value parameters
-- @param `key` The parent key if the value is multi-dimensional (optional)
Expand Down
1 change: 1 addition & 0 deletions spec/plugins/mashape-analytics/alf_serializer_spec.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "kong.tools.ngx_stub"
local fixtures = require "spec.plugins.mashape-analytics.fixtures.requests"
local ALFSerializer = require "kong.plugins.log-serializers.alf"

Expand Down
8 changes: 4 additions & 4 deletions spec/plugins/mashape-analytics/fixtures/requests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ return {
{name = "hello", value = "world"},
{name = "hello", value = "earth"}
},
text = "hello=world&hello=earth"
text = "base64_hello=world&hello=earth"
},
queryString = {
{name = "foo", value = "bar"},
Expand All @@ -66,7 +66,7 @@ return {
content = {
mimeType = "application/json",
size = 934,
text = "{\"message\":\"response body\"}"
text = "base64_{\"message\":\"response body\"}"
},
cookies = {EMPTY_ARRAY_PLACEHOLDER},
headers = {
Expand Down Expand Up @@ -144,7 +144,7 @@ return {
{name = "hello", value = "world"},
{name = "hello", value = "earth"}
},
text = "hello=world&hello=earth"
text = "base64_hello=world&hello=earth"
},
queryString = {
{name = "foo", value = "bar"},
Expand All @@ -157,7 +157,7 @@ return {
content = {
mimeType = "application/json",
size = 934,
text = "{\"message\":\"response body\"}"
text = "base64_{\"message\":\"response body\"}"
},
cookies = {EMPTY_ARRAY_PLACEHOLDER},
headers = {
Expand Down

0 comments on commit 873d828

Please sign in to comment.