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