mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
Add GetResponseBody to redbean (#502)
* Add GetResponseBody to redbean to get access to generated response * Update GetStatus to return status code set by redbean itself (outside of Lua code)
This commit is contained in:
parent
516b68606f
commit
b5904947e9
2 changed files with 15 additions and 2 deletions
|
@ -1055,6 +1055,10 @@ FUNCTIONS
|
||||||
IsPrivateIp or IsLoopbackIp return true. When multiple addresses
|
IsPrivateIp or IsLoopbackIp return true. When multiple addresses
|
||||||
are present in the header, the last/right-most address is used.
|
are present in the header, the last/right-most address is used.
|
||||||
|
|
||||||
|
GetResponseBody() → str
|
||||||
|
Returns the response message body if present or an empty string.
|
||||||
|
Also returns an empty string during streaming.
|
||||||
|
|
||||||
GetClientAddr() → ip:uint32,port:uint16
|
GetClientAddr() → ip:uint32,port:uint16
|
||||||
Returns client socket ip4 address and port, e.g. 0x01020304,31337
|
Returns client socket ip4 address and port, e.g. 0x01020304,31337
|
||||||
would represent 1.2.3.4:31337. Please consider using GetRemoteAddr
|
would represent 1.2.3.4:31337. Please consider using GetRemoteAddr
|
||||||
|
|
|
@ -3365,7 +3365,7 @@ static int LuaSetStatus(lua_State *L) {
|
||||||
|
|
||||||
static int LuaGetStatus(lua_State *L) {
|
static int LuaGetStatus(lua_State *L) {
|
||||||
OnlyCallDuringRequest(L, "GetStatus");
|
OnlyCallDuringRequest(L, "GetStatus");
|
||||||
if (!luaheaderp) {
|
if (!statuscode) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
} else {
|
} else {
|
||||||
lua_pushinteger(L, statuscode);
|
lua_pushinteger(L, statuscode);
|
||||||
|
@ -4418,6 +4418,12 @@ static int LuaGetBody(lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int LuaGetResponseBody(lua_State *L) {
|
||||||
|
OnlyCallDuringRequest(L, "GetResponseBody");
|
||||||
|
lua_pushlstring(L, content, contentlength);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int LuaGetHeader(lua_State *L) {
|
static int LuaGetHeader(lua_State *L) {
|
||||||
int h;
|
int h;
|
||||||
const char *key;
|
const char *key;
|
||||||
|
@ -5074,6 +5080,7 @@ static const char *const kDontAutoComplete[] = {
|
||||||
"GetPayload", // deprecated
|
"GetPayload", // deprecated
|
||||||
"GetPort", //
|
"GetPort", //
|
||||||
"GetRemoteAddr", //
|
"GetRemoteAddr", //
|
||||||
|
"GetResponseBody", //
|
||||||
"GetScheme", //
|
"GetScheme", //
|
||||||
"GetServerAddr", //
|
"GetServerAddr", //
|
||||||
"GetSslIdentity", //
|
"GetSslIdentity", //
|
||||||
|
@ -5181,6 +5188,7 @@ static const luaL_Reg kLuaFuncs[] = {
|
||||||
{"GetRandomBytes", LuaGetRandomBytes}, //
|
{"GetRandomBytes", LuaGetRandomBytes}, //
|
||||||
{"GetRedbeanVersion", LuaGetRedbeanVersion}, //
|
{"GetRedbeanVersion", LuaGetRedbeanVersion}, //
|
||||||
{"GetRemoteAddr", LuaGetRemoteAddr}, //
|
{"GetRemoteAddr", LuaGetRemoteAddr}, //
|
||||||
|
{"GetResponseBody", LuaGetResponseBody}, //
|
||||||
{"GetScheme", LuaGetScheme}, //
|
{"GetScheme", LuaGetScheme}, //
|
||||||
{"GetServerAddr", LuaGetServerAddr}, //
|
{"GetServerAddr", LuaGetServerAddr}, //
|
||||||
{"GetStatus", LuaGetStatus}, //
|
{"GetStatus", LuaGetStatus}, //
|
||||||
|
@ -6378,8 +6386,9 @@ static void InitRequest(void) {
|
||||||
msgsize = 0;
|
msgsize = 0;
|
||||||
loops.n = 0;
|
loops.n = 0;
|
||||||
generator = 0;
|
generator = 0;
|
||||||
luaheaderp = 0;
|
|
||||||
isyielding = 0;
|
isyielding = 0;
|
||||||
|
luaheaderp = 0;
|
||||||
|
statuscode = 0;
|
||||||
contentlength = 0;
|
contentlength = 0;
|
||||||
referrerpolicy = 0;
|
referrerpolicy = 0;
|
||||||
gotcachecontrol = 0;
|
gotcachecontrol = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue