MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / LuaHTTP

Method LuaHTTP

src/lua/LuaHTTP.cpp:43–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41//============================================================================//
42
43LuaHTTP::LuaHTTP(lua_State* LS, const std::string& _url)
44 : httpL(LS)
45 , active(false)
46 , success(false)
47 , fileSize(-1.0)
48 , fileRemoteSize(-1.0)
49 , fileTime(0)
50 , httpCode(0)
51 , url(_url)
52 , postData("")
53 , funcRef(LUA_NOREF)
54 , selfRef(LUA_NOREF) {
55 selfRef = luaL_ref(httpL, LUA_REGISTRYINDEX);
56
57 long timeout = 0;
58 bool noBody = false;
59 bool header = false;
60 std::vector<std::string> httpHeaders;
61
62 int funcArg = 2;
63 if (lua_israwstring(httpL, 2)) {
64 postData = lua_tostring(httpL, 2);
65 funcArg++;
66 }
67 else if (lua_istable(httpL, 2)) {
68 const int table = funcArg;
69 funcArg++;
70 for (lua_pushnil(httpL); lua_next(httpL, table) != 0; lua_pop(httpL, 1)) {
71 if (lua_israwstring(httpL, -2)) {
72 const std::string key = lua_tostring(httpL, -2);
73 if (key == "post") {
74 postData = luaL_checkstring(httpL, -1);
75 }
76 else if (key == "timeout") {
77 timeout = (long)luaL_checkint(httpL, -1);
78 }
79 else if (key == "noBody") {
80 luaL_checktype(httpL, -1, LUA_TBOOLEAN);
81 if (lua_tobool(httpL, -1)) {
82 noBody = true;
83 }
84 }
85 else if (key == "header") {
86 luaL_checktype(httpL, -1, LUA_TBOOLEAN);
87 if (lua_tobool(httpL, -1)) {
88 header = true;
89 }
90 }
91 else if (key == "failOnError") {
92 luaL_checktype(httpL, -1, LUA_TBOOLEAN);
93 if (lua_tobool(httpL, -1)) {
94 setFailOnError();
95 }
96 }
97 else if (key == "httpHeader") {
98 if (lua_israwstring(httpL, -1)) {
99 httpHeaders.push_back(lua_tostring(httpL, -1));
100 }

Callers

nothing calls this directly

Calls 13

lua_israwstringFunction · 0.85
lua_toboolFunction · 0.85
lua_checkgetiFunction · 0.85
luaL_refFunction · 0.50
lua_pushnilFunction · 0.50
lua_nextFunction · 0.50
luaL_checktypeFunction · 0.50
lua_typeFunction · 0.50
lua_gettopFunction · 0.50
luaL_errorFunction · 0.50
lua_pushvalueFunction · 0.50
push_backMethod · 0.45

Tested by

no test coverage detected