diff --git a/tool/net/help.txt b/tool/net/help.txt index d28a856f7..cf276421a 100644 --- a/tool/net/help.txt +++ b/tool/net/help.txt @@ -709,6 +709,10 @@ FUNCTIONS GetScheme() → str Returns scheme from Request-URL, if any. + GetStatus() → int + Returns current status (as set by an earlier SetStatus call) or + `nil` if the status hasn't been set yet. + GetTime() → seconds:number Returns current time as a UNIX timestamp with 0.0001s precision. diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 30e692ce5..fc4e9344e 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -3158,6 +3158,15 @@ static int LuaSetStatus(lua_State *L) { return LuaRespond(L, SetStatus); } +static int LuaGetStatus(lua_State *L) { + OnlyCallDuringRequest(L, "GetStatus"); + if (!luaheaderp) + lua_pushnil(L); + else + lua_pushinteger(L, statuscode); + return 1; +} + static int LuaServeError(lua_State *L) { return LuaRespond(L, ServeError); } @@ -5345,6 +5354,7 @@ static const luaL_Reg kLuaFuncs[] = { {"GetRemoteAddr", LuaGetRemoteAddr}, // {"GetScheme", LuaGetScheme}, // {"GetServerAddr", LuaGetServerAddr}, // + {"GetStatus", LuaGetStatus}, // {"GetTime", LuaGetTime}, // {"GetUrl", LuaGetUrl}, // {"GetUser", LuaGetUser}, //