Files
geedge-jira/attachment/56062/run_script_log_error_replace_resbody.lua
2025-09-14 22:00:20 +00:00

28 lines
755 B
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--[[
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