Files
geedge-jira/attachment/56062/run_script_log_error_replace_resbody.lua

28 lines
755 B
Lua
Raw Normal View History

2025-09-14 22:00:20 +00:00
--[[
case 7.1
HTTP应答体阶段set resp body
--]]
if(tfe.get_current_stage() == "http_req_header")
then
local method = tfe.req.get_method()
if(method == "GET")
then
local req_headers_tab = tfe.req.get_headers()
for k, v in pairs(req_headers_tab) do
if k == "Host" then
tfe.context.host=v
end
end
end
end
if(tfe.get_current_stage() == "http_resp_body")
then
local resp_body = tfe.resp.get_body_data()
if resp_body then
if tfe.context.host=="www.baidu.com" then
tfe.log_error(tfe.context.head)
local replace_resp_body = string.gsub(resp_body, "hello", "nihao");
tfe.resp.set_body_data(replace_resp_body)
end
end
end