[41/50] git commit: TS-2555 adding example and documentation
TS-2555 adding example and documentation Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/01be17ec Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/01be17ec Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/01be17ec Branch: refs/heads/5.0.x Commit: 01be17ecd6ec47b493366feb755db9998bb9146e Parents: e350291 Author: Kit Chan kic...@apache.org Authored: Wed Apr 16 00:38:25 2014 -0700 Committer: Kit Chan kic...@apache.org Committed: Wed Apr 16 00:38:25 2014 -0700 -- doc/reference/plugins/ts_lua.en.rst | 77 +--- plugins/experimental/ts_lua/example/hdr.lua | 37 -- .../ts_lua/example/test_global_hdr.lua | 37 ++ .../experimental/ts_lua/example/test_hdr.lua| 37 ++ 4 files changed, 125 insertions(+), 63 deletions(-) -- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/01be17ec/doc/reference/plugins/ts_lua.en.rst -- diff --git a/doc/reference/plugins/ts_lua.en.rst b/doc/reference/plugins/ts_lua.en.rst index fbf7674..ebcb88c 100644 --- a/doc/reference/plugins/ts_lua.en.rst +++ b/doc/reference/plugins/ts_lua.en.rst @@ -23,16 +23,6 @@ ts-lua Plugin Embed the Power of Lua into TrafficServer. -Status -== - -This module is being tested under our production environment. - -Version -=== - -ts-lua has not been released yet. - Synopsis @@ -242,18 +232,52 @@ Synopsis return 0 end +**test_global_hdr.lua** + +:: + + +function send_response() +ts.client_response.header['Rhost'] = ts.ctx['rhost'] +return 0 +end + +function do_global_read_request() +local req_host = ts.client_request.header.Host + +if req_host == nil then +return 0 +end + +ts.ctx['rhost'] = string.reverse(req_host) + +ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response) + +return 0 +end + Description === -This module embeds Lua, via the standard Lua 5.1 interpreter, into Apache Traffic Server. This module acts as remap plugin of Traffic Server, so we should realize **'do_remap'** function in each lua script. We can write this in remap.config::: +This module embeds Lua, into Apache Traffic Server. This module acts as remap plugin of Traffic Server. In this case we +should provide **'do_remap'** function in each lua script. We can write this in remap.config::: + + map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/usr/lib64/trafficserver/plugins/tslua.so +@pparam=/etc/trafficserver/script/test_hdr.lua - map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/usr/lib64/trafficserver/plugins/tslua.so @pparam=/etc/trafficserver/script/test_hdr.lua +Sometimes we want to receive parameters and process them in the script, we should realize **'\__init__'** function in +the lua script(sethost.lua is a reference), and we can write this in remap.config::: -Sometimes we want to receive parameters and process them in the script, we should realize **'\__init__'** function in the lua script(sethost.lua is a reference), and we can write this in remap.config::: + map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/usr/lib64/trafficserver/plugins/tslua.so +@pparam=/etc/trafficserver/script/sethost.lua @pparam=img03.tbcdn.cn - map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/usr/lib64/trafficserver/plugins/tslua.so @pparam=/etc/trafficserver/script/sethost.lua @pparam=img03.tbcdn.cn +This module can also act as a global plugin of Traffic Server. In this case we should provide one of these functions +(**'do_global_read_request'**, **'do_global_send_request'**, **'do_global_read_response'**, +**'do_global_send_response'**, **'do_global_cache_lookup_complete'**) in each lua script. We can write this in +plugin.config::: + tslua.so /etc/trafficserver/script/test_global_hdr.lua TS API for Lua @@ -262,7 +286,8 @@ TS API for Lua Introduction -The API is exposed to Lua in the form of one standard packages ts. This package is in the default global scope and is always available within lua script. +The API is exposed to Lua in the form of one standard packages ts. This package is in the default global scope and is +always available within lua script. @@ -306,7 +331,7 @@ ts.hook --- **syntax**: *ts.hook(HOOK_POINT, FUNCTION)* -**context**: do_remap or later +**context**: do_remap/do_global_*/later **description**: Hooks are points in http transaction processing where we can step in and do some work. FUNCTION will be called when the http transaction steps in to HOOK_POINT. @@ -323,7 +348,7 @@ Here is an example::: Hook point constants
git commit: TS-2555 adding example and documentation
Repository: trafficserver Updated Branches: refs/heads/master e35029116 - 01be17ecd TS-2555 adding example and documentation Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/01be17ec Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/01be17ec Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/01be17ec Branch: refs/heads/master Commit: 01be17ecd6ec47b493366feb755db9998bb9146e Parents: e350291 Author: Kit Chan kic...@apache.org Authored: Wed Apr 16 00:38:25 2014 -0700 Committer: Kit Chan kic...@apache.org Committed: Wed Apr 16 00:38:25 2014 -0700 -- doc/reference/plugins/ts_lua.en.rst | 77 +--- plugins/experimental/ts_lua/example/hdr.lua | 37 -- .../ts_lua/example/test_global_hdr.lua | 37 ++ .../experimental/ts_lua/example/test_hdr.lua| 37 ++ 4 files changed, 125 insertions(+), 63 deletions(-) -- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/01be17ec/doc/reference/plugins/ts_lua.en.rst -- diff --git a/doc/reference/plugins/ts_lua.en.rst b/doc/reference/plugins/ts_lua.en.rst index fbf7674..ebcb88c 100644 --- a/doc/reference/plugins/ts_lua.en.rst +++ b/doc/reference/plugins/ts_lua.en.rst @@ -23,16 +23,6 @@ ts-lua Plugin Embed the Power of Lua into TrafficServer. -Status -== - -This module is being tested under our production environment. - -Version -=== - -ts-lua has not been released yet. - Synopsis @@ -242,18 +232,52 @@ Synopsis return 0 end +**test_global_hdr.lua** + +:: + + +function send_response() +ts.client_response.header['Rhost'] = ts.ctx['rhost'] +return 0 +end + +function do_global_read_request() +local req_host = ts.client_request.header.Host + +if req_host == nil then +return 0 +end + +ts.ctx['rhost'] = string.reverse(req_host) + +ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response) + +return 0 +end + Description === -This module embeds Lua, via the standard Lua 5.1 interpreter, into Apache Traffic Server. This module acts as remap plugin of Traffic Server, so we should realize **'do_remap'** function in each lua script. We can write this in remap.config::: +This module embeds Lua, into Apache Traffic Server. This module acts as remap plugin of Traffic Server. In this case we +should provide **'do_remap'** function in each lua script. We can write this in remap.config::: + + map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/usr/lib64/trafficserver/plugins/tslua.so +@pparam=/etc/trafficserver/script/test_hdr.lua - map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/usr/lib64/trafficserver/plugins/tslua.so @pparam=/etc/trafficserver/script/test_hdr.lua +Sometimes we want to receive parameters and process them in the script, we should realize **'\__init__'** function in +the lua script(sethost.lua is a reference), and we can write this in remap.config::: -Sometimes we want to receive parameters and process them in the script, we should realize **'\__init__'** function in the lua script(sethost.lua is a reference), and we can write this in remap.config::: + map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/usr/lib64/trafficserver/plugins/tslua.so +@pparam=/etc/trafficserver/script/sethost.lua @pparam=img03.tbcdn.cn - map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/usr/lib64/trafficserver/plugins/tslua.so @pparam=/etc/trafficserver/script/sethost.lua @pparam=img03.tbcdn.cn +This module can also act as a global plugin of Traffic Server. In this case we should provide one of these functions +(**'do_global_read_request'**, **'do_global_send_request'**, **'do_global_read_response'**, +**'do_global_send_response'**, **'do_global_cache_lookup_complete'**) in each lua script. We can write this in +plugin.config::: + tslua.so /etc/trafficserver/script/test_global_hdr.lua TS API for Lua @@ -262,7 +286,8 @@ TS API for Lua Introduction -The API is exposed to Lua in the form of one standard packages ts. This package is in the default global scope and is always available within lua script. +The API is exposed to Lua in the form of one standard packages ts. This package is in the default global scope and is +always available within lua script. @@ -306,7 +331,7 @@ ts.hook --- **syntax**: *ts.hook(HOOK_POINT, FUNCTION)* -**context**: do_remap or later +**context**: do_remap/do_global_*/later **description**: Hooks are points in http transaction processing where we can step in and do some work. FUNCTION will be called when the http transaction steps in to