Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update remap_lua.md #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions doc/remap_lua.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
Remap��Lua
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
Expand All @@ -62,7 +62,7 @@ Remap
http www.taobao.com {
map / http://www.taobao.com.inner.taobao.com {
script send_request {
-- �ѻ�Դrequest Host �ij�www.tmall.com
-- 把回源request Host 改成www.tmall.com
ts.client_request.header['Host'] = 'www.tmall.com'
}
}
Expand All @@ -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"
}
}
Expand All @@ -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'
}
}
Expand All @@ -96,17 +96,17 @@ 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'
end
}

script send_response {
-- ����Cache״̬ͷ
-- 添加Cache状态头
ts.client_response.header['Cache-Status'] = ts.ctx['cstatus']
}
}
Expand Down