This is an automated email from the ASF dual-hosted git repository. rrm 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 17366ab Lua plugin: add ts.server_response.get_maxage() 17366ab is described below commit 17366abe1b1af649672cb53df6a7772b92472c39 Author: Emanuele Rocca <e...@wikimedia.org> AuthorDate: Wed May 13 10:09:26 2020 +0200 Lua plugin: add ts.server_response.get_maxage() --- doc/admin-guide/plugins/lua.en.rst | 26 ++++++++++++++++++++++++++ plugins/lua/ts_lua_server_response.c | 17 +++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/doc/admin-guide/plugins/lua.en.rst b/doc/admin-guide/plugins/lua.en.rst index 1b2b178..c282da6 100644 --- a/doc/admin-guide/plugins/lua.en.rst +++ b/doc/admin-guide/plugins/lua.en.rst @@ -2267,6 +2267,32 @@ ts.server_response.is_cacheable :ref:`TOP <admin-plugins-ts-lua>` +ts.server_response.get_maxage +------------------------------ +**syntax:** *maxage = ts.server_response.get_maxage()* + +**context:** function @ TS_LUA_HOOK_READ_RESPONSE_HDR hook point or later. + +**description:** Return the maximum age of the server response in seconds if specified by Cache-Control, -1 otherwise. + +For example: + +:: + + function debug_long_maxage() + maxage = ts.server_response.get_maxage() + if ts.server_response.is_cacheable() and maxage > 86400 then + ts.debug('Cacheable response with maxage=' .. maxage) + end + end + + function do_remap() + ts.hook(TS_LUA_HOOK_READ_RESPONSE_HDR, debug_long_maxage) + return 0 + end + +:ref:`TOP <admin-plugins-ts-lua>` + ts.server_response.set_version ------------------------------ **syntax:** *ts.server_response.set_version(VERSION_STR)* diff --git a/plugins/lua/ts_lua_server_response.c b/plugins/lua/ts_lua_server_response.c index 1c04866..b14cc32 100644 --- a/plugins/lua/ts_lua_server_response.c +++ b/plugins/lua/ts_lua_server_response.c @@ -44,6 +44,7 @@ static int ts_lua_server_response_get_version(lua_State *L); static int ts_lua_server_response_set_version(lua_State *L); static int ts_lua_server_response_is_cacheable(lua_State *L); +static int ts_lua_server_response_get_maxage(lua_State *L); void ts_lua_inject_server_response_api(lua_State *L) @@ -155,6 +156,8 @@ ts_lua_inject_server_response_misc_api(lua_State *L) lua_pushcfunction(L, ts_lua_server_response_is_cacheable); lua_setfield(L, -2, "is_cacheable"); + lua_pushcfunction(L, ts_lua_server_response_get_maxage); + lua_setfield(L, -2, "get_maxage"); } static int @@ -381,3 +384,17 @@ ts_lua_server_response_is_cacheable(lua_State *L) return 1; } + +static int +ts_lua_server_response_get_maxage(lua_State *L) +{ + ts_lua_http_ctx *http_ctx; + + GET_HTTP_CONTEXT(http_ctx, L); + + TS_LUA_CHECK_SERVER_RESPONSE_HDR(http_ctx); + + lua_pushnumber(L, TSHttpTxnGetMaxAge(http_ctx->txnp, http_ctx->server_response_bufp)); + + return 1; +}