mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-05 17:30:27 +00:00
Update redbean Fetch to accept table with parameters (#97).
This commit is contained in:
parent
ea83cc0ad0
commit
bb7f9c6270
1 changed files with 10 additions and 4 deletions
|
@ -3702,15 +3702,21 @@ static int LuaFetch(lua_State *L) {
|
|||
.ai_flags = AI_NUMERICSERV};
|
||||
|
||||
/*
|
||||
* Get args.
|
||||
* Get args: url [, body | {method = "PUT", body = "..."}]
|
||||
*/
|
||||
urlarg = luaL_checklstring(L, 1, &urlarglen);
|
||||
if (lua_isnoneornil(L, 2)) {
|
||||
if (lua_istable(L, 2)) {
|
||||
lua_settop(L, 2); // discard any extra arguments
|
||||
lua_getfield(L, 2, "body");
|
||||
body = luaL_optstring(L, -1, "");
|
||||
lua_getfield(L, 2, "method");
|
||||
method = GetHttpMethod(luaL_optstring(L, -1, ""), lua_rawlen(L, -1));
|
||||
lua_settop(L, 2); // drop all added elements to keep the stack balanced
|
||||
} else if (lua_isnoneornil(L, 2)) {
|
||||
body = "";
|
||||
method = kHttpGet;
|
||||
} else {
|
||||
size_t bodylen;
|
||||
body = luaL_checklstring(L, 2, &bodylen);
|
||||
body = luaL_checkstring(L, 2);
|
||||
method = kHttpPost;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue