Skip to content

[Question] How to modify the response body after kong.response.exit(in access phase)? #13225

Closed Answered by luozhouyang
luozhouyang asked this question in Help
Discussion options

You must be logged in to vote

SOLVED! I write a custom plugin to modify the response body. Here is the key steps:

  • Drop the Content-Length header in header_filter phase
  • Set the new body in body_filter phase

Here is an example:

function _M:header_filter(conf)
    kong.response.clear_header("Content-Length")
end

function _M:body_filter(conf)
    -- replace the body here
    local new_body = ...
    return kong.response.set_raw_body(new_body)
end

Replies: 2 comments

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 StarlightIbuki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants