trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kic...@apache.org
Subject trafficserver git commit: TS-4230: support matrix style parameter in ts_lua plugin. This closes #499
Date Sun, 13 Mar 2016 20:23:52 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master 702324236 -> 0e419b47c


TS-4230: support matrix style parameter in ts_lua plugin. This closes #499


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/0e419b47
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/0e419b47
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/0e419b47

Branch: refs/heads/master
Commit: 0e419b47cc2a652dab6d4812418ecb5b4fa22bf4
Parents: 7023242
Author: Kit Chan <kichan@apache.org>
Authored: Sun Mar 13 13:23:45 2016 -0700
Committer: Kit Chan <kichan@apache.org>
Committed: Sun Mar 13 13:23:45 2016 -0700

----------------------------------------------------------------------
 doc/admin-guide/plugins/ts_lua.en.rst           | 83 ++++++++++++++++++++
 .../experimental/ts_lua/ts_lua_client_request.c | 51 ++++++++++++
 .../experimental/ts_lua/ts_lua_server_request.c | 56 +++++++++++++
 3 files changed, 190 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0e419b47/doc/admin-guide/plugins/ts_lua.en.rst
----------------------------------------------------------------------
diff --git a/doc/admin-guide/plugins/ts_lua.en.rst b/doc/admin-guide/plugins/ts_lua.en.rst
index 8c1f9c8..caad94f 100644
--- a/doc/admin-guide/plugins/ts_lua.en.rst
+++ b/doc/admin-guide/plugins/ts_lua.en.rst
@@ -580,6 +580,45 @@ ts.client_request.set_uri_args
 
 `TOP <#ts-lua-plugin>`_
 
+ts.client_request.get_uri_params
+--------------------------------
+**syntax:** *ts.client_request.get_uri_params()*
+
+**context:** do_remap or do_global_* or later
+
+**description:** This function can be used to retrieve the client request's parameter string.
+
+Here is an example:
+
+::
+
+    function do_remap()
+        local query = ts.client_request.get_uri_params()
+        print(query)
+    end
+
+Then ``GET /st;a=1`` will yield the output:
+
+``a=1``
+
+
+`TOP <#ts-lua-plugin>`_
+
+ts.client_request.set_uri_params
+--------------------------------
+**syntax:** *ts.client_request.set_uri_params(PARAMETER_STRING)*
+
+**context:** do_remap or do_global_*
+
+**description:** This function can be used to override the client request's parameter string.
+
+::
+
+    ts.client_request.set_uri_params('n=6')
+
+
+`TOP <#ts-lua-plugin>`_
+
 ts.client_request.get_url
 -------------------------
 **syntax:** *ts.client_request.get_url()*
@@ -1212,6 +1251,50 @@ ts.server_request.set_uri_args
 
 `TOP <#ts-lua-plugin>`_
 
+ts.server_request.get_uri_params
+--------------------------------
+**syntax:** *ts.server_request.get_uri_params()*
+
+**context:** function @ TS_LUA_HOOK_SEND_REQUEST_HDR hook point or later
+
+**description:** This function can be used to retrieve the server request's parameter string.
+
+Here is an example:
+
+::
+
+    function send_request()
+        local query = ts.server_request.get_uri_params()
+        print(query)
+    end
+
+    function do_remap()
+        ts.hook(TS_LUA_HOOK_SEND_REQUEST_HDR, send_request)
+        return 0
+    end
+
+Then ``GET /st;a=1`` will yield the output:
+
+``a=1``
+
+
+`TOP <#ts-lua-plugin>`_
+
+ts.server_request.set_uri_params
+--------------------------------
+**syntax:** *ts.server_request.set_uri_params(PARAMETER_STRING)*
+
+**context:** function @ TS_LUA_HOOK_SEND_REQUEST_HDR hook point
+
+**description:** This function can be used to override the server request's parameter string.
+
+::
+
+    ts.server_request.set_uri_params('n=6')
+
+
+`TOP <#ts-lua-plugin>`_
+
 ts.server_request.header.HEADER
 -------------------------------
 **syntax:** *ts.server_request.header.HEADER = VALUE*

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0e419b47/plugins/experimental/ts_lua/ts_lua_client_request.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/ts_lua_client_request.c b/plugins/experimental/ts_lua/ts_lua_client_request.c
index 7a729ab..a90fb71 100644
--- a/plugins/experimental/ts_lua/ts_lua_client_request.c
+++ b/plugins/experimental/ts_lua/ts_lua_client_request.c
@@ -40,6 +40,8 @@ static int ts_lua_client_request_get_uri(lua_State *L);
 static int ts_lua_client_request_set_uri(lua_State *L);
 static int ts_lua_client_request_set_uri_args(lua_State *L);
 static int ts_lua_client_request_get_uri_args(lua_State *L);
+static int ts_lua_client_request_set_uri_params(lua_State *L);
+static int ts_lua_client_request_get_uri_params(lua_State *L);
 static int ts_lua_client_request_get_method(lua_State *L);
 static int ts_lua_client_request_set_method(lua_State *L);
 static int ts_lua_client_request_get_version(lua_State *L);
@@ -54,6 +56,7 @@ static void ts_lua_inject_client_request_headers_api(lua_State *L);
 static void ts_lua_inject_client_request_url_api(lua_State *L);
 static void ts_lua_inject_client_request_uri_api(lua_State *L);
 static void ts_lua_inject_client_request_args_api(lua_State *L);
+static void ts_lua_inject_client_request_params_api(lua_State *L);
 static void ts_lua_inject_client_request_method_api(lua_State *L);
 static void ts_lua_inject_client_request_version_api(lua_State *L);
 static void ts_lua_inject_client_request_body_size_api(lua_State *L);
@@ -76,6 +79,7 @@ ts_lua_inject_client_request_api(lua_State *L)
   ts_lua_inject_client_request_url_api(L);
   ts_lua_inject_client_request_uri_api(L);
   ts_lua_inject_client_request_args_api(L);
+  ts_lua_inject_client_request_params_api(L);
   ts_lua_inject_client_request_method_api(L);
   ts_lua_inject_client_request_version_api(L);
   ts_lua_inject_client_request_body_size_api(L);
@@ -568,6 +572,53 @@ ts_lua_client_request_set_uri_args(lua_State *L)
   return 0;
 }
 
+static void
+ts_lua_inject_client_request_params_api(lua_State *L)
+{
+  lua_pushcfunction(L, ts_lua_client_request_set_uri_params);
+  lua_setfield(L, -2, "set_uri_params");
+
+  lua_pushcfunction(L, ts_lua_client_request_get_uri_params);
+  lua_setfield(L, -2, "get_uri_params");
+}
+
+static int
+ts_lua_client_request_get_uri_params(lua_State *L)
+{
+  const char *param;
+  int param_len;
+
+  ts_lua_http_ctx *http_ctx;
+
+  GET_HTTP_CONTEXT(http_ctx, L);
+
+  param = TSUrlHttpParamsGet(http_ctx->client_request_bufp, http_ctx->client_request_url,
&param_len);
+
+  if (param && param_len > 0) {
+    lua_pushlstring(L, param, param_len);
+  } else {
+    lua_pushnil(L);
+  }
+
+  return 1;
+}
+
+static int
+ts_lua_client_request_set_uri_params(lua_State *L)
+{
+  const char *param;
+  size_t param_len;
+
+  ts_lua_http_ctx *http_ctx;
+
+  GET_HTTP_CONTEXT(http_ctx, L);
+
+  param = luaL_checklstring(L, 1, &param_len);
+  TSUrlHttpParamsSet(http_ctx->client_request_bufp, http_ctx->client_request_url, param,
param_len);
+
+  return 0;
+}
+
 static int
 ts_lua_client_request_client_addr_get_ip(lua_State *L)
 {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0e419b47/plugins/experimental/ts_lua/ts_lua_server_request.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/ts_lua_server_request.c b/plugins/experimental/ts_lua/ts_lua_server_request.c
index 326d266..83d05a4 100644
--- a/plugins/experimental/ts_lua/ts_lua_server_request.c
+++ b/plugins/experimental/ts_lua/ts_lua_server_request.c
@@ -50,6 +50,7 @@ static void ts_lua_inject_server_request_get_header_size_api(lua_State *L);
 static void ts_lua_inject_server_request_get_body_size_api(lua_State *L);
 static void ts_lua_inject_server_request_uri_api(lua_State *L);
 static void ts_lua_inject_server_request_uri_args_api(lua_State *L);
+static void ts_lua_inject_server_request_uri_params_api(lua_State *L);
 
 static int ts_lua_server_request_header_get(lua_State *L);
 static int ts_lua_server_request_header_set(lua_State *L);
@@ -60,6 +61,8 @@ static int ts_lua_server_request_get_uri(lua_State *L);
 static int ts_lua_server_request_set_uri(lua_State *L);
 static int ts_lua_server_request_set_uri_args(lua_State *L);
 static int ts_lua_server_request_get_uri_args(lua_State *L);
+static int ts_lua_server_request_set_uri_params(lua_State *L);
+static int ts_lua_server_request_get_uri_params(lua_State *L);
 
 static int ts_lua_server_request_server_addr_get_ip(lua_State *L);
 static int ts_lua_server_request_server_addr_get_port(lua_State *L);
@@ -79,6 +82,7 @@ ts_lua_inject_server_request_api(lua_State *L)
 
   ts_lua_inject_server_request_uri_api(L);
   ts_lua_inject_server_request_uri_args_api(L);
+  ts_lua_inject_server_request_uri_params_api(L);
 
   lua_setfield(L, -2, "server_request");
 }
@@ -424,6 +428,58 @@ ts_lua_server_request_get_uri_args(lua_State *L)
   return 1;
 }
 
+static void
+ts_lua_inject_server_request_uri_params_api(lua_State *L)
+{
+  lua_pushcfunction(L, ts_lua_server_request_set_uri_params);
+  lua_setfield(L, -2, "set_uri_params");
+
+  lua_pushcfunction(L, ts_lua_server_request_get_uri_params);
+  lua_setfield(L, -2, "get_uri_params");
+}
+
+static int
+ts_lua_server_request_set_uri_params(lua_State *L)
+{
+  const char *param;
+  size_t param_len;
+
+  ts_lua_http_ctx *http_ctx;
+
+  GET_HTTP_CONTEXT(http_ctx, L);
+
+  TS_LUA_CHECK_SERVER_REQUEST_URL(http_ctx);
+
+  param = luaL_checklstring(L, 1, &param_len);
+  TSUrlHttpParamsSet(http_ctx->server_request_bufp, http_ctx->server_request_url, param,
param_len);
+
+  return 0;
+}
+
+static int
+ts_lua_server_request_get_uri_params(lua_State *L)
+{
+  const char *param;
+  int param_len;
+
+  ts_lua_http_ctx *http_ctx;
+
+  GET_HTTP_CONTEXT(http_ctx, L);
+
+  TS_LUA_CHECK_SERVER_REQUEST_URL(http_ctx);
+
+  param = TSUrlHttpParamsGet(http_ctx->server_request_bufp, http_ctx->server_request_url,
&param_len);
+
+  if (param && param_len > 0) {
+    lua_pushlstring(L, param, param_len);
+
+  } else {
+    lua_pushnil(L);
+  }
+
+  return 1;
+}
+
 static int
 ts_lua_server_request_server_addr_get_ip(lua_State *L)
 {


Mime
View raw message