You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ki...@apache.org on 2018/03/14 23:58:09 UTC

[trafficserver] branch master updated: Support TSRemapFromUrlGet/TSRemapToUrlGet in ts_lua plugin

This is an automated email from the ASF dual-hosted git repository.

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new a534275  Support TSRemapFromUrlGet/TSRemapToUrlGet in ts_lua plugin
a534275 is described below

commit a534275715811adf7478e6d3ffe7a015bd137384
Author: Kit Chan <ki...@apache.org>
AuthorDate: Sat Mar 10 17:07:05 2018 -0800

    Support TSRemapFromUrlGet/TSRemapToUrlGet in ts_lua plugin
---
 doc/admin-guide/plugins/ts_lua.en.rst     | 54 ++++++++++++++++++++++++++
 plugins/experimental/ts_lua/ts_lua_http.c | 63 +++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)

diff --git a/doc/admin-guide/plugins/ts_lua.en.rst b/doc/admin-guide/plugins/ts_lua.en.rst
index 342a859..cf8dff6 100644
--- a/doc/admin-guide/plugins/ts_lua.en.rst
+++ b/doc/admin-guide/plugins/ts_lua.en.rst
@@ -196,6 +196,22 @@ We should write this TAG in records.config(If TAG is missing, default TAG will b
 
 `TOP <#ts-lua-plugin>`_
 
+ts.error
+--------
+**syntax:** *ts.error(MESSAGE)*
+
+**context:** global
+
+**description**: Log the MESSAGE to error.log
+
+Here is an example:
+
+::
+
+       ts.error('This is an error message')
+
+`TOP <#ts-lua-plugin>`_
+
 Remap status constants
 ----------------------
 **context:** do_remap
@@ -2373,6 +2389,44 @@ Here is an example
 
 `TOP <#ts-lua-plugin>`_
 
+ts.http.get_remap_from_url
+--------------------------
+**syntax:** *ts.http.get_remap_from_url()*
+
+**context:** do_global_post_remap
+
+**description:** This function can be used to get the *from* URL in the matching line in :file:`remap.config`.
+
+Here is an example
+
+::
+
+    function do_global_post_remap()
+        local from_url = ts.http.get_remap_from_url()
+        ts.debug(from_url)
+    end
+
+`TOP <#ts-lua-plugin>`_
+
+ts.http.get_remap_to_url
+------------------------
+**syntax:** *ts.http.get_remap_to_url()*
+
+**context:** do_global_post_remap
+
+**description:** This function can be used to get the *to* URL in the matching line in :file:`remap.config`.
+
+Here is an example
+
+::
+
+    function do_global_post_remap()
+        local to_url = ts.http.get_remap_to_url()
+        ts.debug(to_url)
+    end
+
+`TOP <#ts-lua-plugin>`_
+
 Server state constants
 ----------------------
 **context:** global
diff --git a/plugins/experimental/ts_lua/ts_lua_http.c b/plugins/experimental/ts_lua/ts_lua_http.c
index e59284c..245638b 100644
--- a/plugins/experimental/ts_lua/ts_lua_http.c
+++ b/plugins/experimental/ts_lua/ts_lua_http.c
@@ -99,6 +99,9 @@ static int ts_lua_http_transaction_count(lua_State *L);
 static int ts_lua_http_redirect_url_set(lua_State *L);
 static int ts_lua_http_get_server_state(lua_State *L);
 
+static int ts_lua_http_get_remap_from_url(lua_State *L);
+static int ts_lua_http_get_remap_to_url(lua_State *L);
+
 static void ts_lua_inject_server_state_variables(lua_State *L);
 
 static void ts_lua_inject_http_resp_transform_api(lua_State *L);
@@ -229,6 +232,12 @@ ts_lua_inject_http_misc_api(lua_State *L)
   lua_pushcfunction(L, ts_lua_http_get_server_state);
   lua_setfield(L, -2, "get_server_state");
 
+  lua_pushcfunction(L, ts_lua_http_get_remap_from_url);
+  lua_setfield(L, -2, "get_remap_from_url");
+
+  lua_pushcfunction(L, ts_lua_http_get_remap_to_url);
+  lua_setfield(L, -2, "get_remap_to_url");
+
   ts_lua_inject_server_state_variables(L);
 }
 
@@ -746,6 +755,60 @@ ts_lua_http_get_server_state(lua_State *L)
 }
 
 static int
+ts_lua_http_get_remap_from_url(lua_State *L)
+{
+  TSMLoc url = TS_NULL_MLOC;
+  char *str  = NULL;
+  int len;
+  ts_lua_http_ctx *http_ctx;
+
+  GET_HTTP_CONTEXT(http_ctx, L);
+
+  if (TSRemapFromUrlGet(http_ctx->txnp, &url) != TS_SUCCESS) {
+    lua_pushnil(L);
+    goto done;
+  }
+
+  str = TSUrlStringGet(NULL, url, &len);
+
+  lua_pushlstring(L, str, len >= TS_LUA_MAX_URL_LENGTH ? TS_LUA_MAX_URL_LENGTH - 1 : len);
+
+done:
+  if (str != NULL) {
+    TSfree(str);
+  }
+
+  return 1;
+}
+
+static int
+ts_lua_http_get_remap_to_url(lua_State *L)
+{
+  TSMLoc url = TS_NULL_MLOC;
+  char *str  = NULL;
+  int len;
+  ts_lua_http_ctx *http_ctx;
+
+  GET_HTTP_CONTEXT(http_ctx, L);
+
+  if (TSRemapToUrlGet(http_ctx->txnp, &url) != TS_SUCCESS) {
+    lua_pushnil(L);
+    goto done;
+  }
+
+  str = TSUrlStringGet(NULL, url, &len);
+
+  lua_pushlstring(L, str, len >= TS_LUA_MAX_URL_LENGTH ? TS_LUA_MAX_URL_LENGTH - 1 : len);
+
+done:
+  if (str != NULL) {
+    TSfree(str);
+  }
+
+  return 1;
+}
+
+static int
 ts_lua_http_resp_transform_get_upstream_bytes(lua_State *L)
 {
   ts_lua_http_transform_ctx *transform_ctx;

-- 
To stop receiving notification emails like this one, please contact
kichan@apache.org.