You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2014/04/17 18:44:40 UTC
[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 <ki...@apache.org>
Authored: Wed Apr 16 00:38:25 2014 -0700
Committer: Kit Chan <ki...@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
--------------------
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
TS_LUA_HOOK_CACHE_LOOKUP_COMPLETE
TS_LUA_HOOK_SEND_REQUEST_HDR
@@ -339,7 +364,7 @@ ts.ctx
------
**syntax**: *ts.ctx[KEY]*
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
**description**: This table can be used to store per-request Lua context data and has a life time identical to the current request.
@@ -418,7 +443,7 @@ ts.http.resp_cache_transformed
------------------------------
**syntax**: *ts.http.resp_cache_transformed(BOOL)*
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
**description**: This function can be used to tell trafficserver whether to cache the transformed data.
@@ -446,7 +471,7 @@ ts.http.resp_cache_untransformed
--------------------------------
**syntax**: *ts.http.resp_cache_untransformed(BOOL)*
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
**description**: This function can be used to tell trafficserver whether to cache the untransformed data.
@@ -474,7 +499,7 @@ ts.client_request.client_addr.get_addr
--------------------------------------
**syntax**: *ts.client_request.client_addr.get_addr()*
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
**description**: This function can be used to get socket address of the client.
@@ -492,7 +517,7 @@ ts.client_request.get_method
----------------------------
**syntax**: *ts.client_request.get_method()*
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
**description**: This function can be used to retrieve the current request's request method name. String like "GET" or
"POST" is returned.
@@ -511,7 +536,7 @@ ts.client_request.get_url
-------------------------
**syntax**: *ts.client_request.get_url()*
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
**description**: This function can be used to retrieve the whole request's url.
@@ -520,7 +545,7 @@ ts.client_request.get_uri
-------------------------
**syntax**: *ts.client_request.get_uri()*
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
**description**: This function can be used to retrieve the request's path.
@@ -538,7 +563,7 @@ ts.client_request.get_uri_args
------------------------------
**syntax**: *ts.client_request.get_uri_args()*
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
**description**: This function can be used to retrieve the request's query string.
@@ -560,7 +585,7 @@ ts.client_request.header.HEADER
**syntax**: *VALUE = ts.client_request.header.HEADER*
-**context**: do_remap or later
+**context**: do_remap/do_global_*/later
**description**: Set, add to, clear or get the current request's HEADER.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/01be17ec/plugins/experimental/ts_lua/example/hdr.lua
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/example/hdr.lua b/plugins/experimental/ts_lua/example/hdr.lua
deleted file mode 100644
index b79a63b..0000000
--- a/plugins/experimental/ts_lua/example/hdr.lua
+++ /dev/null
@@ -1,37 +0,0 @@
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you under the Apache License, Version 2.0 (the
--- "License"); you may not use this file except in compliance
--- with the License. You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
-
-
-function send_response()
- ts.client_response.header['Rhost'] = ts.ctx['rhost']
- return 0
-end
-
-
-function do_remap()
- 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
-
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/01be17ec/plugins/experimental/ts_lua/example/test_global_hdr.lua
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/example/test_global_hdr.lua b/plugins/experimental/ts_lua/example/test_global_hdr.lua
new file mode 100644
index 0000000..012dbcf
--- /dev/null
+++ b/plugins/experimental/ts_lua/example/test_global_hdr.lua
@@ -0,0 +1,37 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+
+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
+
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/01be17ec/plugins/experimental/ts_lua/example/test_hdr.lua
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/example/test_hdr.lua b/plugins/experimental/ts_lua/example/test_hdr.lua
new file mode 100644
index 0000000..b79a63b
--- /dev/null
+++ b/plugins/experimental/ts_lua/example/test_hdr.lua
@@ -0,0 +1,37 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+
+function send_response()
+ ts.client_response.header['Rhost'] = ts.ctx['rhost']
+ return 0
+end
+
+
+function do_remap()
+ 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
+