Remap与Lua
ts-lua 接口文档https://github.com/portl4t/ts-lua
Remap 可支持配置Lua Hook点的五个阶段
do_remap
-
read_response
读取回源response 阶段,该阶段可以读取、修改回源接收的response header
send_response
cache_lookup_complete
Cache 读取阶段,该阶段可以判断读出的Cache状态,读取Cache中的response header等
配置示例
do_remap
http www.taobao.com {
map / http://www.taobao.com.inner.taobao.com {
script do_remap {
-- 判断Useragent 做跳转
ts.ctx['is_forbidden'] = 0
if string.find(uagent, 'haoyu') then
ts.ctx['is_forbidden'] = 1
ts.http.set_resp(302, "302 Moved")
return TS_LUA_REMAP_DID_REMAP_STOP
}
script send_response {
if ts.ctx['is_forbidden'] == 1 then
ts.client_response.header['Location'] = 'http://err.haoyu.com/'
return 0
end
}
}
}
send_request
-
http www.taobao.com {
map / http://www.taobao.com.inner.taobao.com {
script send_response {
-- 添加Response Header
ts.client_response.header['Test'] = 'yes'
}
}
cache_lookup_complete