| 200 | } |
| 201 | |
| 202 | static int |
| 203 | ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetch_info *fi) |
| 204 | { |
| 205 | TSCont contp; |
| 206 | int tb, flags, host_len, n; |
| 207 | int cl, ht, ua; |
| 208 | const char *method, *key, *value, *body, *opt; |
| 209 | const char *addr, *ptr, *host; |
| 210 | size_t method_len, key_len, value_len, body_len; |
| 211 | size_t addr_len, opt_len, i, left; |
| 212 | char c; |
| 213 | struct sockaddr clientaddr; |
| 214 | char buf[32]; |
| 215 | |
| 216 | tb = lua_istable(L, -1); |
| 217 | |
| 218 | /* method */ |
| 219 | if (tb) { |
| 220 | lua_pushlstring(L, "method", sizeof("method") - 1); |
| 221 | lua_gettable(L, -2); |
| 222 | if (lua_isstring(L, -1)) { |
| 223 | method = luaL_checklstring(L, -1, &method_len); |
| 224 | |
| 225 | } else { |
| 226 | method = "GET"; |
| 227 | method_len = sizeof("GET") - 1; |
| 228 | } |
| 229 | |
| 230 | lua_pop(L, 1); |
| 231 | |
| 232 | } else { |
| 233 | method = "GET"; |
| 234 | method_len = sizeof("GET") - 1; |
| 235 | } |
| 236 | |
| 237 | /* body */ |
| 238 | body = nullptr; |
| 239 | body_len = 0; |
| 240 | |
| 241 | if (tb) { |
| 242 | lua_pushlstring(L, "body", sizeof("body") - 1); |
| 243 | lua_gettable(L, -2); |
| 244 | |
| 245 | if (lua_isstring(L, -1)) { |
| 246 | body = luaL_checklstring(L, -1, &body_len); |
| 247 | } |
| 248 | |
| 249 | lua_pop(L, 1); |
| 250 | } |
| 251 | |
| 252 | /* cliaddr */ |
| 253 | memset(&clientaddr, 0, sizeof(clientaddr)); |
| 254 | |
| 255 | if (tb) { |
| 256 | lua_pushlstring(L, "cliaddr", sizeof("cliaddr") - 1); |
| 257 | lua_gettable(L, -2); |
| 258 | |
| 259 | if (lua_isstring(L, -1)) { |
no test coverage detected