From 7aa89771ce90a237db638899522798318f908d65 Mon Sep 17 00:00:00 2001 From: Kit Chan Date: Sat, 3 Oct 2020 21:17:10 -0700 Subject: [PATCH] Add support for server protocol stack API --- doc/admin-guide/plugins/lua.en.rst | 62 ++++++++++++++++++++++++++++++ plugins/lua/ts_lua_http.c | 21 ++++++++++ 2 files changed, 83 insertions(+) diff --git a/doc/admin-guide/plugins/lua.en.rst b/doc/admin-guide/plugins/lua.en.rst index c282da6e887..b8819aabb07 100644 --- a/doc/admin-guide/plugins/lua.en.rst +++ b/doc/admin-guide/plugins/lua.en.rst @@ -299,6 +299,46 @@ Here is an example: :ref:`TOP ` +ts.status +--------- +**syntax:** *ts.status(MESSAGE)* + +**context:** global + +**description**: Log the MESSAGE to error.log as status + +:ref:`TOP ` + +ts.note +------- +**syntax:** *ts.note(MESSAGE)* + +**context:** global + +**description**: Log the MESSAGE to error.log as note + +:ref:`TOP ` + +ts.warning +---------- +**syntax:** *ts.warning(MESSAGE)* + +**context:** global + +**description**: Log the MESSAGE to error.log as warning + +:ref:`TOP ` + +ts.alert +-------- +**syntax:** *ts.alert(MESSAGE)* + +**context:** global + +**description**: Log the MESSAGE to error.log as alert + +:ref:`TOP ` + TS Basic Internal Information ----------------------------- **syntax:** *ts.get_install_dir()* @@ -2770,6 +2810,28 @@ Here is an example: :ref:`TOP ` +ts.http.get_server_protocol_stack +--------------------------------- +**syntax:** *ts.http.get_server_protocol_stack()* + +**context:** do_global_read_response or later + +**description:** This function can be used to get server protocol stack information + +Here is an example: + +:: + + function do_global_read_response() + local stack = {ts.http.get_server_protocol_stack()} + for k,v in pairs(stack) do + ts.debug(v) + end + return 0 + end + +:ref:`TOP ` + ts.http.server_push ------------------- **syntax:** *ts.http.server_push()* diff --git a/plugins/lua/ts_lua_http.c b/plugins/lua/ts_lua_http.c index 9ea883ce7b7..5763f62f423 100644 --- a/plugins/lua/ts_lua_http.c +++ b/plugins/lua/ts_lua_http.c @@ -85,6 +85,7 @@ 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_get_server_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); @@ -218,6 +219,9 @@ 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_get_server_protocol_stack); + lua_setfield(L, -2, "get_server_protocol_stack"); + lua_pushcfunction(L, ts_lua_http_server_push); lua_setfield(L, -2, "server_push"); @@ -654,6 +658,23 @@ ts_lua_http_get_client_protocol_stack(lua_State *L) return count; } +static int +ts_lua_http_get_server_protocol_stack(lua_State *L) +{ + char const *results[10]; + int count = 0; + ts_lua_http_ctx *http_ctx; + + GET_HTTP_CONTEXT(http_ctx, L); + + TSHttpTxnServerProtocolStackGet(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) {