Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions doc/admin-guide/plugins/lua.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,46 @@ Here is an example:

:ref:`TOP <admin-plugins-ts-lua>`

ts.status
---------
**syntax:** *ts.status(MESSAGE)*

**context:** global

**description**: Log the MESSAGE to error.log as status

:ref:`TOP <admin-plugins-ts-lua>`

ts.note
-------
**syntax:** *ts.note(MESSAGE)*

**context:** global

**description**: Log the MESSAGE to error.log as note

:ref:`TOP <admin-plugins-ts-lua>`

ts.warning
----------
**syntax:** *ts.warning(MESSAGE)*

**context:** global

**description**: Log the MESSAGE to error.log as warning

:ref:`TOP <admin-plugins-ts-lua>`

ts.alert
--------
**syntax:** *ts.alert(MESSAGE)*

**context:** global

**description**: Log the MESSAGE to error.log as alert

:ref:`TOP <admin-plugins-ts-lua>`

TS Basic Internal Information
-----------------------------
**syntax:** *ts.get_install_dir()*
Expand Down Expand Up @@ -2770,6 +2810,28 @@ Here is an example:

:ref:`TOP <admin-plugins-ts-lua>`

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 <admin-plugins-ts-lua>`

ts.http.server_push
-------------------
**syntax:** *ts.http.server_push()*
Expand Down
21 changes: 21 additions & 0 deletions plugins/lua/ts_lua_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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)
{
Expand Down