diff --git a/CHANGES b/CHANGES index b47204e99d..d0bd9d540d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) mod_lua: Add r:wspeek for checking if there is any data waiting on the line + [Daniel Gruno] + *) mod_proxy_wstunnel: Avoid busy loop on client errors, drop message IDs 02445, 02446, and 02448 to TRACE1 from DEBUG. PR 56145. [Joffroy Christen , Eric Covener] diff --git a/docs/manual/mod/mod_lua.xml b/docs/manual/mod/mod_lua.xml index 4d26b8c5db..3b06d1e563 100644 --- a/docs/manual/mod/mod_lua.xml +++ b/docs/manual/mod/mod_lua.xml @@ -1023,6 +1023,18 @@ if r:wsupgrade() then end + +r:wspeek() -- Checks if any data is ready to be read + +-- Sleep while nothing is being sent to us... +while r:wspeek() == false do + r.usleep(50000) +end +-- We have data ready! +local line = r:wsread() + + +
Logging Functions diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index e9af3bd937..78bed5b017 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -2152,6 +2152,27 @@ static apr_status_t lua_websocket_readbytes(conn_rec* c, char* buffer, return rv; } +static int lua_websocket_peek(lua_State *L) +{ + apr_status_t rv; + apr_bucket_brigade *brigade; + + request_rec *r = ap_lua_check_request_rec(L, 1); + + brigade = apr_brigade_create(r->connection->pool, + r->connection->bucket_alloc); + rv = ap_get_brigade(r->connection->input_filters, brigade, + AP_MODE_READBYTES, APR_NONBLOCK_READ, 1); + if (rv == APR_SUCCESS) { + lua_pushboolean(L, 1); + } + else { + lua_pushboolean(L, 0); + } + apr_brigade_cleanup(brigade); + return 1; +} + static int lua_websocket_read(lua_State *L) { apr_socket_t *sock; @@ -2789,6 +2810,8 @@ void ap_lua_load_request_lmodule(lua_State *L, apr_pool_t *p) makefun(&lua_websocket_greet, APL_REQ_FUNTYPE_LUACFUN, p)); apr_hash_set(dispatch, "wsread", APR_HASH_KEY_STRING, makefun(&lua_websocket_read, APL_REQ_FUNTYPE_LUACFUN, p)); + apr_hash_set(dispatch, "wspeek", APR_HASH_KEY_STRING, + makefun(&lua_websocket_peek, APL_REQ_FUNTYPE_LUACFUN, p)); apr_hash_set(dispatch, "wswrite", APR_HASH_KEY_STRING, makefun(&lua_websocket_write, APL_REQ_FUNTYPE_LUACFUN, p)); apr_hash_set(dispatch, "wsclose", APR_HASH_KEY_STRING,