Skip to content

Commit

Permalink
refactor(tests) request transformer plugin (Kong#1305)
Browse files Browse the repository at this point in the history
* Refactored tests for the request transformer plugin. Including a bugfix and tests for the test-helpers.
  • Loading branch information
Tieske authored Jul 1, 2016
1 parent b9f0e4f commit 5051c33
Show file tree
Hide file tree
Showing 11 changed files with 1,693 additions and 757 deletions.
9 changes: 4 additions & 5 deletions kong/plugins/request-transformer/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ local req_clear_header = ngx.req.clear_header
local encode_args = ngx.encode_args
local ngx_decode_args = ngx.decode_args
local type = type
local string_len = string.len
local string_find = string.find
local pcall = pcall

Expand Down Expand Up @@ -160,7 +159,7 @@ end

local function transform_json_body(conf, body, content_length)
local removed, replaced, added, appended = false, false, false, false
local content_length = (body and string_len(body)) or 0
local content_length = (body and #body) or 0
local parameters = parse_json(body)
if parameters == nil and content_length > 0 then return false, nil end

Expand Down Expand Up @@ -267,7 +266,7 @@ local function transform_multipart_body(conf, body, content_length, content_type

if #conf.add.body > 0 then
for _, name, value in iter(conf.add.body) do
if not parameters[name] then
if not parameters:get(name) then
parameters:set_simple(name, value)
added = true
end
Expand All @@ -288,7 +287,7 @@ local function transform_body(conf)
req_read_body()
local body = req_get_body_data()
local is_body_transformed = false
local content_length = (body and string_len(body)) or 0
local content_length = (body and #body) or 0

if content_type == ENCODED then
is_body_transformed, body = transform_url_encoded_body(conf, body, content_length)
Expand All @@ -300,7 +299,7 @@ local function transform_body(conf)

if is_body_transformed then
req_set_body_data(body)
req_set_header(CONTENT_LENGTH, string_len(body))
req_set_header(CONTENT_LENGTH, #body)
end
end

Expand Down
Loading

0 comments on commit 5051c33

Please sign in to comment.