Skip to content

Commit

Permalink
Fix response transformer hang. See issues #1260 and #1207
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed May 27, 2016
1 parent 8e6c84e commit a34f6ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kong/plugins/response-transformer/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ local BasePlugin = require "kong.plugins.base_plugin"
local body_filter = require "kong.plugins.response-transformer.body_transformer"
local header_filter = require "kong.plugins.response-transformer.header_transformer"

local is_body_transform_set = header_filter.is_body_transform_set
local is_json_body = header_filter.is_json_body

local ResponseTransformerHandler = BasePlugin:extend()


function ResponseTransformerHandler:new()
ResponseTransformerHandler.super.new(self, "response-transformer")
end
Expand All @@ -20,7 +24,8 @@ end

function ResponseTransformerHandler:body_filter(conf)
ResponseTransformerHandler.super.body_filter(self)
if body_filter.is_json_body(ngx.header["content-type"]) then

if is_body_transform_set(conf) and is_json_body(ngx.header["content-type"]) then
local chunk, eof = ngx.arg[1], ngx.arg[2]
if eof then
local body = body_filter.transform_json_body(conf, ngx.ctx.buffer)
Expand Down
4 changes: 4 additions & 0 deletions kong/plugins/response-transformer/header_transformer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ local function is_body_transform_set(conf)
return #conf.add.json > 0 or #conf.remove.json > 0 or #conf.replace.json > 0 or #conf.append.json > 0
end

-- export utility functions
_M.is_json_body = is_json_body
_M.is_body_transform_set = is_body_transform_set

---
-- # Example:
-- ngx.headers = header_filter.transform_headers(conf, ngx.headers)
Expand Down

0 comments on commit a34f6ce

Please sign in to comment.