Skip to content

Commit 4a70bcb

Browse files
committed
Add. Support set null as array in multi API
1 parent e3b5c92 commit 4a70bcb

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/lcmulti.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,17 @@ static int lcurl_opt_set_string_array_(lua_State *L, int opt){
424424
lcurl_multi_t *p = lcurl_getmulti(L);
425425
CURLMcode code;
426426
int n;
427-
luaL_argcheck(L, lua_type(L, 2) == LUA_TTABLE, 2, "array expected");
428-
n = lua_rawlen(L, 2);
427+
428+
if (lutil_is_null(L, 2)) {
429+
n = 0;
430+
}
431+
else {
432+
luaL_argcheck(L, lua_type(L, 2) == LUA_TTABLE, 2, "array expected");
433+
n = lua_rawlen(L, 2);
434+
}
435+
429436
if(n == 0){
430-
char *val[] = {NULL};
431-
code = curl_multi_setopt(p->curl, opt, val);
437+
code = curl_multi_setopt(p->curl, opt, 0);
432438
}
433439
else{
434440
int i;

test/test_easy.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,11 +1064,12 @@ end
10641064

10651065
local _ENV = TEST_CASE'set_null' if ENABLE then
10661066

1067-
local c
1067+
local c, m
10681068

10691069
function teardown()
10701070
if c then c:close() end
1071-
c = nil
1071+
if m then m:close() end
1072+
m, c = nil
10721073
end
10731074

10741075
function test_string()
@@ -1109,6 +1110,14 @@ function test_slist_via_table()
11091110
assert_not_match("X%-Custom:%s*value\r\n", headers)
11101111
end
11111112

1113+
function test_multi_set_array()
1114+
m = curl.multi()
1115+
m:setopt_pipelining_site_bl{
1116+
'127.0.0.1'
1117+
}
1118+
assert_equal(m, m:setopt_pipelining_site_bl(null))
1119+
end
1120+
11121121
end
11131122

11141123
RUN()

0 commit comments

Comments
 (0)