Skip to content

how to get response body #7403

Answered by eddie04
eddie04 asked this question in Help
Discussion options

You must be logged in to vote

I reinstalled my custom plugin,it's ok now,there is no problem.

function plugin:access(plugin_conf)

  kong.service.request.enable_buffering()
  
end
function plugin:log(plugin_conf)
  local event_state="failed"
  local fail_reason= ""

  if kong.response.get_status() >= 200 and kong.response.get_status() < 300 then
    event_state = "success"
  else
    local res_body_string = tostring(kong.service.response.get_raw_body())
    kong.log.debug("response body:",res_body_string)
    fail_reason = res_body_string
  end
  
end

BTW I installed Kong in Docker container, and http version is 1.1.

request: "POST /api/whitelist/query HTTP/1.1"

Thanks a lot, @bungle !

Replies: 9 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by kikito
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
3 participants
Converted from issue

This discussion was converted from issue #7090 on May 28, 2021 10:27.