From e2857700cbe0013d8542f1d1c3066d82e6c9d8e1 Mon Sep 17 00:00:00 2001 From: acache Date: Fri, 13 Mar 2015 23:28:46 +0800 Subject: [PATCH] Update remap_lua.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把if cached_status == TS_LUA_CACHE_LOOKUP_HIT_FRESH then改为if TS_LUA_CACHE_LOOKUP_HIT_FRESH == cached_status then,不然判断不成功。 --- doc/remap_lua.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/doc/remap_lua.md b/doc/remap_lua.md index 7a49101..6d1e879 100644 --- a/doc/remap_lua.md +++ b/doc/remap_lua.md @@ -1,43 +1,43 @@ -RemapLua +Remap与Lua ========== -°汾luaѿǶ뵽remap.configָ֧Ļhttp header +在新版本里,lua已可嵌入到remap.config里,支持更灵活的基于http header编程 -ts-lua ӿĵhttps://github.com/portl4t/ts-lua +ts-lua 接口文档https://github.com/portl4t/ts-lua -### ˵ -Remap ֧Lua Hook׶ +### 配置说明 +Remap 可支持配置Lua Hook点的五个阶段 * do_remap - remapǰ׶Σý׶ο޸Ĵ洢keyܾȵȲ + remap前阶段,该阶段可以修改存储key,拒绝服务等等操作 * send_request - Դrequest ׶Σý׶οԶȡ޸ĻԴrequest header + 回源发送request 阶段,该阶段可以读取、修改回源request header * read_response - ȡԴresponse ׶Σý׶οԶȡ޸ĻԴյresponse header + 读取回源response 阶段,该阶段可以读取、修改回源接收的response header * send_response - ͸client response ׶Σý׶οԶȡ޸ķ͸ûresponse header + 发送给client response 阶段,该阶段可以读取、修改发送给用户response header * cache_lookup_complete - Cache ȡ׶Σý׶οж϶Cache״̬ȡCacheеresponse header + Cache 读取阶段,该阶段可以判断读出的Cache状态,读取Cache中的response header等 -### ʾ +### 配置示例 -> ע һremap ʹö״̬״̬ϳһűʹ +> 注: 一个remap 里可以使用多个状态,多个状态配合成一个脚本使用 * do_remap http www.taobao.com { map / http://www.taobao.com.inner.taobao.com { script do_remap { - -- жUseragent ת + -- 判断Useragent 做跳转 ts.ctx['is_forbidden'] = 0 local uagent = ts.client_request.header['User-Agent'] if string.find(uagent, 'haoyu') then @@ -62,7 +62,7 @@ Remap http www.taobao.com { map / http://www.taobao.com.inner.taobao.com { script send_request { - -- ѻԴrequest Host ijwww.tmall.com + -- 把回源request Host 改成www.tmall.com ts.client_request.header['Host'] = 'www.tmall.com' } } @@ -74,7 +74,7 @@ Remap http www.taobao.com { map / http://www.taobao.com.inner.taobao.com { script read_response { - -- Accept-Test ั + -- 按照Accept-Test 做多副本缓存 ts.server_response.header['Vary'] = "Accept-Test" } } @@ -85,7 +85,7 @@ Remap http www.taobao.com { map / http://www.taobao.com.inner.taobao.com { script send_response { - -- Response Header + -- 添加Response Header ts.client_response.header['Test'] = 'yes' } } @@ -96,9 +96,9 @@ Remap http www.taobao.com { map / http://www.taobao.com.inner.taobao.com { script cache_lookup_complete { - -- Cache ״̬ + -- 获得Cache 状态 local cache_status = ts.http.get_cache_lookup_status() - if cached_status == TS_LUA_CACHE_LOOKUP_HIT_FRESH then + if TS_LUA_CACHE_LOOKUP_HIT_FRESH == cached_status then ts.ctx['cstatus'] = 'hit' else ts.ctx['cstatus'] = 'miss' @@ -106,7 +106,7 @@ Remap } script send_response { - -- Cache״̬ͷ + -- 添加Cache状态头 ts.client_response.header['Cache-Status'] = ts.ctx['cstatus'] } }