This is an automated email from the ASF dual-hosted git repository.
kichan pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 73bd908 TS-4990: adding new APIs support to ts_lua plugin
73bd908 is described below
commit 73bd90849c1aa4d5a39e1ba0d8650e343fa3a699
Author: Kit Chan <[email protected]>
AuthorDate: Wed Oct 19 02:14:52 2016 -0700
TS-4990: adding new APIs support to ts_lua plugin
---
doc/admin-guide/plugins/ts_lua.en.rst | 149 +++++++++++++++++++++
plugins/experimental/ts_lua/ts_lua_http.c | 131 ++++++++++++++++++
.../experimental/ts_lua/ts_lua_server_request.c | 56 ++++++++
3 files changed, 336 insertions(+)
diff --git a/doc/admin-guide/plugins/ts_lua.en.rst
b/doc/admin-guide/plugins/ts_lua.en.rst
index a5dc6e5..33993f8 100644
--- a/doc/admin-guide/plugins/ts_lua.en.rst
+++ b/doc/admin-guide/plugins/ts_lua.en.rst
@@ -948,6 +948,42 @@ ts.http.set_cache_lookup_url
`TOP <#ts-lua-plugin>`_
+ts.http.get_parent_proxy
+------------------------
+**syntax:** *ts.http.get_parent_proxy()*
+
+**context:** do_global_cache_lookup_complete
+
+**description:** This function can be used to get the parent proxy host and
port.
+
+Here is an example
+
+::
+
+ function cache_lookup()
+ ts.http.set_parent_proxy('test1.test.com', 1111)
+ host, port = ts.http.get_parent_proxy()
+ ts.debug(host)
+ ts.debug(port)
+ end
+
+ function do_remap()
+ ts.hook(TS_LUA_HOOK_CACHE_LOOKUP_COMPLETE, cache_lookup)
+ return 0
+ end
+
+`TOP <#ts-lua-plugin>`_
+
+ts.http.set_parent_proxy
+------------------------
+**syntax:** *ts.http.set_parent_proxy()*
+
+**context:** do_global_cache_lookup_complete
+
+**description:** This function can be used to set the parent proxy host and
name.
+
+`TOP <#ts-lua-plugin>`_
+
ts.http.get_parent_selection_url
--------------------------------
**syntax:** *ts.http.get_parent_selection_url()*
@@ -1424,6 +1460,38 @@ We will get the output:
`TOP <#ts-lua-plugin>`_
+ts.server_request.server_addr.set_addr
+--------------------------------------
+**syntax:** *ts.server_request.server_addr.set_addr()*
+
+**context:** no later than function @ TS_LUA_HOOK_OS_DNS hook point
+
+**description**: This function can be used to set socket address of the origin
server.
+
+The ts.server_request.server_addr.set_addr function requires three inputs, ip
is a string, port and family is number.
+
+Here is an example:
+
+::
+
+ function do_global_read_request()
+ ts.server_request.server_addr.set_addr("192.168.231.17", 80,
TS_LUA_AF_INET)
+ end
+
+`TOP <#ts-lua-plugin>`_
+
+Socket address family
+---------------------
+**context:** global
+
+::
+
+ TS_LUA_AF_INET (2)
+ TS_LUA_AF_INET6 (10)
+
+
+`TOP <#ts-lua-plugin>`_
+
ts.server_request.server_addr.get_addr
--------------------------------------
**syntax:** *ts.server_request.server_addr.get_addr()*
@@ -2116,6 +2184,87 @@ This function is usually called in
do_global_read_request function
`TOP <#ts-lua-plugin>`_
+ts.http.get_client_protocol_stack
+---------------------------------
+**syntax:** *ts.http.get_client_protocol_stack()*
+
+**context:** do_remap/do_os_response or do_global_* or later
+
+**description:** This function can be used to get client protocol stack
information
+
+Here is an example:
+
+::
+
+ function do_global_read_request()
+ local stack = {ts.http.get_client_protocol_stack()}
+ for k,v in pairs(stack) do
+ ts.debug(v)
+ end
+ return 0
+ end
+
+`TOP <#ts-lua-plugin>`_
+
+ts.http.server_push
+-------------------
+**syntax:** *ts.http.server_push()*
+
+**context:** do_remap/do_os_response or do_global_* or later
+
+**description:** This function can do http/2 server push for the input url
+
+Here is an example:
+
+::
+
+ function do_global_read_request()
+ ts.http.server_push("https://test.com/test.js")
+ return 0
+ end
+
+`TOP <#ts-lua-plugin>`_
+
+ts.http.is_websocket
+--------------------
+**syntax:** *ts.http.is_websocket()*
+
+**context:** do_remap/do_os_response or do_global_* or later
+
+**description:** This function can be used to tell if the transacton is
websocket
+
+Here is an example:
+
+::
+
+ function do_global_read_request()
+ local flag = ts.http.is_websocket()
+ ts.debug(flag)
+ return 0
+ end
+
+`TOP <#ts-lua-plugin>`_
+
+ts.http.get_plugin_tag
+----------------------
+**syntax:** *ts.http.get_plugin_tag()*
+
+**context:** do_remap/do_os_response or do_global_* or later
+
+**description:** This function can be used to get plugin tag of a transaction
+
+Here is an example:
+
+::
+
+ function do_global_read_request()
+ local tag = ts.http.get_plugin_tag() or ''
+ ts.debug(tag)
+ return 0
+ end
+
+`TOP <#ts-lua-plugin>`_
+
ts.http.id
----------
**syntax:** *ts.http.id()*
diff --git a/plugins/experimental/ts_lua/ts_lua_http.c
b/plugins/experimental/ts_lua/ts_lua_http.c
index 4e7cc3e..ff06c34 100644
--- a/plugins/experimental/ts_lua/ts_lua_http.c
+++ b/plugins/experimental/ts_lua/ts_lua_http.c
@@ -77,6 +77,8 @@ static int ts_lua_http_set_cache_lookup_status(lua_State *L);
static int ts_lua_http_set_cache_url(lua_State *L);
static int ts_lua_http_get_cache_lookup_url(lua_State *L);
static int ts_lua_http_set_cache_lookup_url(lua_State *L);
+static int ts_lua_http_get_parent_proxy(lua_State *L);
+static int ts_lua_http_set_parent_proxy(lua_State *L);
static int ts_lua_http_get_parent_selection_url(lua_State *L);
static int ts_lua_http_set_parent_selection_url(lua_State *L);
static int ts_lua_http_set_server_resp_no_store(lua_State *L);
@@ -86,6 +88,10 @@ static void
ts_lua_inject_cache_lookup_result_variables(lua_State *L);
static int ts_lua_http_resp_cache_transformed(lua_State *L);
static int ts_lua_http_resp_cache_untransformed(lua_State *L);
+static int ts_lua_http_get_client_protocol_stack(lua_State *L);
+static int ts_lua_http_server_push(lua_State *L);
+static int ts_lua_http_is_websocket(lua_State *L);
+static int ts_lua_http_get_plugin_tag(lua_State *L);
static int ts_lua_http_get_id(lua_State *L);
static int ts_lua_http_is_internal_request(lua_State *L);
static int ts_lua_http_skip_remapping_set(lua_State *L);
@@ -147,6 +153,12 @@ ts_lua_inject_http_cache_api(lua_State *L)
lua_pushcfunction(L, ts_lua_http_set_cache_lookup_url);
lua_setfield(L, -2, "set_cache_lookup_url");
+ lua_pushcfunction(L, ts_lua_http_get_parent_proxy);
+ lua_setfield(L, -2, "get_parent_proxy");
+
+ lua_pushcfunction(L, ts_lua_http_set_parent_proxy);
+ lua_setfield(L, -2, "set_parent_proxy");
+
lua_pushcfunction(L, ts_lua_http_get_parent_selection_url);
lua_setfield(L, -2, "get_parent_selection_url");
@@ -187,6 +199,18 @@ ts_lua_inject_http_resp_transform_api(lua_State *L)
static void
ts_lua_inject_http_misc_api(lua_State *L)
{
+ lua_pushcfunction(L, ts_lua_http_get_client_protocol_stack);
+ lua_setfield(L, -2, "get_client_protocol_stack");
+
+ lua_pushcfunction(L, ts_lua_http_server_push);
+ lua_setfield(L, -2, "server_push");
+
+ lua_pushcfunction(L, ts_lua_http_is_websocket);
+ lua_setfield(L, -2, "is_websocket");
+
+ lua_pushcfunction(L, ts_lua_http_get_plugin_tag);
+ lua_setfield(L, -2, "get_plugin_tag");
+
lua_pushcfunction(L, ts_lua_http_get_id);
lua_setfield(L, -2, "id");
@@ -387,6 +411,54 @@ ts_lua_http_set_cache_lookup_url(lua_State *L)
}
static int
+ts_lua_http_get_parent_proxy(lua_State *L)
+{
+ const char *hostname = NULL;
+ int port = 0;
+ ts_lua_http_ctx *http_ctx;
+
+ GET_HTTP_CONTEXT(http_ctx, L);
+
+ TSHttpTxnParentProxyGet(http_ctx->txnp, &hostname, &port);
+
+ if (hostname == NULL) {
+ lua_pushnil(L);
+ } else {
+ lua_pushstring(L, hostname);
+ }
+ lua_pushnumber(L, port);
+
+ return 2;
+}
+
+static int
+ts_lua_http_set_parent_proxy(lua_State *L)
+{
+ int n = 0;
+ const char *hostname;
+ size_t hostname_len;
+ int port = 0;
+ const char *target;
+
+ ts_lua_http_ctx *http_ctx;
+
+ GET_HTTP_CONTEXT(http_ctx, L);
+
+ n = lua_gettop(L);
+
+ if (n == 2) {
+ hostname = luaL_checklstring(L, 1, &hostname_len);
+ target = TSstrndup(hostname, hostname_len);
+ port = luaL_checkinteger(L, 2);
+ TSHttpTxnParentProxySet(http_ctx->txnp, target, port);
+ } else {
+ return luaL_error(L, "incorrect # of arguments for set_parent_proxy,
receiving %d instead of 2", n);
+ }
+
+ return 0;
+}
+
+static int
ts_lua_http_get_parent_selection_url(lua_State *L)
{
char output[TS_LUA_MAX_URL_LENGTH];
@@ -526,6 +598,65 @@ ts_lua_http_resp_cache_untransformed(lua_State *L)
}
static int
+ts_lua_http_get_client_protocol_stack(lua_State *L)
+{
+ char const *results[10];
+ int count = 0;
+ ts_lua_http_ctx *http_ctx;
+
+ GET_HTTP_CONTEXT(http_ctx, L);
+
+ TSHttpTxnClientProtocolStackGet(http_ctx->txnp, 10, results, &count);
+ for (int i = 0; i < count; i++) {
+ lua_pushstring(L, results[i]);
+ }
+
+ return count;
+}
+
+static int
+ts_lua_http_server_push(lua_State *L)
+{
+ const char *url;
+ const char *push_url;
+ size_t url_len;
+ ts_lua_http_ctx *http_ctx;
+
+ GET_HTTP_CONTEXT(http_ctx, L);
+
+ url = luaL_checklstring(L, 1, &url_len);
+ push_url = TSstrndup(url, url_len);
+ TSHttpTxnServerPush(http_ctx->txnp, push_url, url_len);
+
+ return 0;
+}
+
+static int
+ts_lua_http_is_websocket(lua_State *L)
+{
+ ts_lua_http_ctx *http_ctx;
+
+ GET_HTTP_CONTEXT(http_ctx, L);
+
+ lua_pushboolean(L, TSHttpTxnIsWebsocket(http_ctx->txnp));
+
+ return 1;
+}
+
+static int
+ts_lua_http_get_plugin_tag(lua_State *L)
+{
+ ts_lua_http_ctx *http_ctx;
+
+ GET_HTTP_CONTEXT(http_ctx, L);
+
+ const char *tag = TSHttpTxnPluginTagGet(http_ctx->txnp);
+ lua_pushstring(L, tag);
+
+ return 1;
+}
+
+static int
ts_lua_http_get_id(lua_State *L)
{
ts_lua_http_ctx *http_ctx;
diff --git a/plugins/experimental/ts_lua/ts_lua_server_request.c
b/plugins/experimental/ts_lua/ts_lua_server_request.c
index 3f6de97..d67f894 100644
--- a/plugins/experimental/ts_lua/ts_lua_server_request.c
+++ b/plugins/experimental/ts_lua/ts_lua_server_request.c
@@ -71,6 +71,7 @@ static int ts_lua_server_request_set_url_scheme(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);
static int ts_lua_server_request_server_addr_get_addr(lua_State *L);
+static int ts_lua_server_request_server_addr_set_addr(lua_State *L);
static int ts_lua_server_request_server_addr_get_outgoing_port(lua_State *L);
void
@@ -113,10 +114,19 @@ ts_lua_inject_server_request_server_addr_api(lua_State *L)
lua_pushcfunction(L, ts_lua_server_request_server_addr_get_addr);
lua_setfield(L, -2, "get_addr");
+ lua_pushcfunction(L, ts_lua_server_request_server_addr_set_addr);
+ lua_setfield(L, -2, "set_addr");
+
lua_pushcfunction(L, ts_lua_server_request_server_addr_get_outgoing_port);
lua_setfield(L, -2, "get_outgoing_port");
lua_setfield(L, -2, "server_addr");
+
+ lua_pushinteger(L, AF_INET);
+ lua_setglobal(L, "TS_LUA_AF_INET");
+
+ lua_pushinteger(L, AF_INET6);
+ lua_setglobal(L, "TS_LUA_AF_INET6");
}
static void
@@ -756,3 +766,49 @@ ts_lua_server_request_server_addr_get_addr(lua_State *L)
return 3;
}
+
+static int
+ts_lua_server_request_server_addr_set_addr(lua_State *L)
+{
+ union {
+ struct sockaddr_in sin4;
+ struct sockaddr_in6 sin6;
+ struct sockaddr sa;
+ } addr;
+ ts_lua_http_ctx *http_ctx;
+ int n;
+ int port;
+ int family;
+ const char *sip;
+ size_t sip_len;
+
+ GET_HTTP_CONTEXT(http_ctx, L);
+
+ n = lua_gettop(L);
+
+ if (n == 3) {
+ sip = luaL_checklstring(L, 1, &sip_len);
+ port = luaL_checknumber(L, 2);
+ family = luaL_checknumber(L, 3);
+
+ if (family == AF_INET) {
+ addr.sin4.sin_family = AF_INET;
+ addr.sin4.sin_port = htons(port);
+ if (!inet_pton(family, sip, &addr.sin4.sin_addr)) {
+ return luaL_error(L, "invalid ipv4 address");
+ }
+ } else {
+ addr.sin6.sin6_family = AF_INET6;
+ addr.sin6.sin6_port = htons(port);
+ if (!inet_pton(family, sip, &addr.sin6.sin6_addr)) {
+ return luaL_error(L, "invalid ipv6 address");
+ }
+ }
+
+ TSHttpTxnServerAddrSet(http_ctx->txnp, &addr.sa);
+ } else {
+ return luaL_error(L, "incorrect # of arguments to
ts.server_request.addr.set_addr, receiving %d instead of 3", n);
+ }
+
+ return 0;
+}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].