Skip to content

Commit

Permalink
Update handler.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineJac authored Mar 13, 2024
1 parent 459a0be commit 4feeb7d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions kong/plugins/ai-proxy/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,22 @@ function _M:body_filter(conf)
end

if kong.ctx.shared.skip_response_transformer then
local response_body
local response_body, status
if kong.ctx.shared.parsed_response then
response_body = kong.ctx.shared.parsed_response
elseif kong.response.get_status() == 200 then
response_body = kong.service.response.get_raw_body()
if response_body then
status, response_body = pcall( function()
return kong.service.response.get_raw_body()
end)
if status and response_body then
local is_gzip = kong.response.get_header("Content-Encoding") == "gzip"

if is_gzip then
response_body = kong_utils.inflate_gzip(response_body)
end
else
kong.log.warn("issue when retrieve the response body for analytics in the body filter phase.",
" Please check AI request transformer plugin response")
end
end

Expand Down

0 comments on commit 4feeb7d

Please sign in to comment.