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
27 changes: 26 additions & 1 deletion doc/admin-guide/plugins/lua.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2977,7 +2977,7 @@ ts.http.transaction_count

**context:** do_remap/do_os_response or do_global_* or later

**description:** This function returns the number of transaction in this connection
**description:** This function returns the number of transaction in this client connection

Here is an example

Expand All @@ -2991,6 +2991,16 @@ Here is an example

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

ts.http.server_transaction_count
--------------------------------
**syntax:** *ts.http.server_transaction_count()*

**context:** do_remap/do_os_response or do_global_* or later

**description:** This function returns the number of transaction in this server connection

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

ts.http.redirect_url_set
------------------------
**syntax:** *ts.http.redirect_url_set()*
Expand Down Expand Up @@ -4235,6 +4245,21 @@ ts.mgmt.get_string

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

ts.mgmt.add_config_file
-----------------------
**syntax:** *ts.mgmt.add_config_file(parent, filename)*

**context:** do_remap/do_os_response or do_global_* or later.

**description:** This function invokes ``TSMgmtConfigFileAdd`` API.

::

remap = ts.mgmt.get_string('proxy.config.url_remap.filename')
ts.mgmt.add_config_file(remap, '/etc/my.config')

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

ts.stat_create
--------------
**syntax:** *val = ts.stat_create(STAT_NAME, RECORDDATA_TYPE, PERSISTENT, SYNC)*
Expand Down
10 changes: 10 additions & 0 deletions plugins/lua/ts_lua_fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,19 @@ ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetc
return 0;
}
}
} else {
if (TS_ERROR == TSIpStringToAddr(TS_LUA_FETCH_CLIENT_ADDRPORT, TS_LUA_FETCH_CLIENT_ADDRPORT_LEN, &clientaddr)) {
TSError("[ts_lua][%s] Default client ip parse failed!", TS_LUA_DEBUG_TAG);
return 0;
}
}

lua_pop(L, 1);
} else {
if (TS_ERROR == TSIpStringToAddr(TS_LUA_FETCH_CLIENT_ADDRPORT, TS_LUA_FETCH_CLIENT_ADDRPORT_LEN, &clientaddr)) {
TSError("[ts_lua][%s] Default client ip parse failed!", TS_LUA_DEBUG_TAG);
return 0;
}
}

/* option */
Expand Down
17 changes: 17 additions & 0 deletions plugins/lua/ts_lua_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static int ts_lua_http_is_internal_request(lua_State *L);
static int ts_lua_http_is_aborted(lua_State *L);
static int ts_lua_http_skip_remapping_set(lua_State *L);
static int ts_lua_http_transaction_count(lua_State *L);
static int ts_lua_http_server_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);

Expand Down Expand Up @@ -249,6 +250,9 @@ ts_lua_inject_http_misc_api(lua_State *L)
lua_pushcfunction(L, ts_lua_http_transaction_count);
lua_setfield(L, -2, "transaction_count");

lua_pushcfunction(L, ts_lua_http_server_transaction_count);
lua_setfield(L, -2, "server_transaction_count");

lua_pushcfunction(L, ts_lua_http_redirect_url_set);
lua_setfield(L, -2, "redirect_url_set");

Expand Down Expand Up @@ -806,6 +810,19 @@ ts_lua_http_transaction_count(lua_State *L)
return 1;
}

static int
ts_lua_http_server_transaction_count(lua_State *L)
{
ts_lua_http_ctx *http_ctx;

GET_HTTP_CONTEXT(http_ctx, L);

int n = TSHttpTxnServerSsnTransactionCount(http_ctx->txnp);
lua_pushnumber(L, n);

return 1;
}

static int
ts_lua_http_redirect_url_set(lua_State *L)
{
Expand Down
20 changes: 20 additions & 0 deletions plugins/lua/ts_lua_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static int ts_lua_mgmt_get_int(lua_State *L);
static int ts_lua_mgmt_get_counter(lua_State *L);
static int ts_lua_mgmt_get_float(lua_State *L);
static int ts_lua_mgmt_get_string(lua_State *L);
static int ts_lua_mgmt_add_config_file(lua_State *L);

void
ts_lua_inject_mgmt_api(lua_State *L)
Expand All @@ -40,6 +41,9 @@ ts_lua_inject_mgmt_api(lua_State *L)
lua_pushcfunction(L, ts_lua_mgmt_get_string);
lua_setfield(L, -2, "get_string");

lua_pushcfunction(L, ts_lua_mgmt_add_config_file);
lua_setfield(L, -2, "add_config_file");

lua_setfield(L, -2, "mgmt");
}

Expand Down Expand Up @@ -107,3 +111,19 @@ ts_lua_mgmt_get_string(lua_State *L)

return 0;
}

static int
ts_lua_mgmt_add_config_file(lua_State *L)
{
const char *parent;
const char *filename;
size_t parent_len = 0, filename_len = 0;

if (lua_gettop(L) == 2) {
filename = luaL_checklstring(L, 2, &filename_len);
parent = luaL_checklstring(L, 1, &parent_len);
TSMgmtConfigFileAdd(parent, filename);
}

return 0;
}