Modifying the body of a response
-- This script is used to test the modification of a JSON based response. It
-- will change the 'modified' field in the JSON payload from false to
-- true.
local cjson = require "cjson"
-- Only modify the response if the content-type is 'application/json'
if HTTPResponse.getHeader("content-type") == "application/json" then
local payload = cjson.decode(HTTPResponse.getBody())
payload["modified"] = true
HTTPResponse.setBody(cjson.encode(payload))
end