Remap与Lua

    ts-lua 接口文档https://github.com/portl4t/ts-lua

    Remap 可支持配置Lua Hook点的五个阶段

    • do_remap

    • read_response

      1. 读取回源response 阶段,该阶段可以读取、修改回源接收的response header
    • send_response

    • cache_lookup_complete

      1. Cache 读取阶段,该阶段可以判断读出的Cache状态,读取Cache中的response header

    配置示例

    • do_remap

      1. http www.taobao.com {
      2. map / http://www.taobao.com.inner.taobao.com {
      3. script do_remap {
      4. -- 判断Useragent 做跳转
      5. ts.ctx['is_forbidden'] = 0
      6. if string.find(uagent, 'haoyu') then
      7. ts.ctx['is_forbidden'] = 1
      8. ts.http.set_resp(302, "302 Moved")
      9. return TS_LUA_REMAP_DID_REMAP_STOP
      10. }
      11. script send_response {
      12. if ts.ctx['is_forbidden'] == 1 then
      13. ts.client_response.header['Location'] = 'http://err.haoyu.com/'
      14. return 0
      15. end
      16. }
      17. }
      18. }
    • send_request

      1. http www.taobao.com {
      2. map / http://www.taobao.com.inner.taobao.com {
      3. script send_response {
      4. -- 添加Response Header
      5. ts.client_response.header['Test'] = 'yes'
      6. }
      7. }
    • cache_lookup_complete