Skip to content

Commit 3208536

Browse files
committed
Merge pull request #66 from moteus/setopt_stream_depends
Fix. cURL set stream depends options
2 parents fb8c79e + 2cbac6e commit 3208536

File tree

2 files changed

+127
-4
lines changed

2 files changed

+127
-4
lines changed

src/lua/cURL/impl/cURL.lua

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ local function make_iterator(self, perform)
116116
end
117117
end
118118

119-
120119
-- name = <string>/<stream>/<file>/<buffer>/<content>
121120
--
122121
-- <stream> = {
@@ -504,23 +503,60 @@ function Easy:setopt_httppost(form)
504503
return setopt_httppost(self, form:handle())
505504
end
506505

506+
if curl.OPT_STREAM_DEPENDS then
507+
508+
local setopt_stream_depends = wrap_function("setopt_stream_depends")
509+
function Easy:setopt_stream_depends(easy)
510+
return setopt_stream_depends(self, easy:handle())
511+
end
512+
513+
local setopt_stream_depends_e = wrap_function("setopt_stream_depends_e")
514+
function Easy:setopt_stream_depends_e(easy)
515+
return setopt_stream_depends_e(self, easy:handle())
516+
end
517+
518+
end
519+
507520
local setopt = wrap_function("setopt")
521+
local custom_setopt = {
522+
[curl.OPT_HTTPPOST or true] = 'setopt_httppost';
523+
[curl.OPT_STREAM_DEPENDS or true] = 'setopt_stream_depends';
524+
[curl.OPT_STREAM_DEPENDS_E or true] = 'setopt_stream_depends_e';
525+
}
526+
custom_setopt[true] = nil
527+
508528
function Easy:setopt(k, v)
509529
if type(k) == 'table' then
510530
local t = k
511531

532+
local t2
512533
local hpost = t.httppost or t[curl.OPT_HTTPPOST]
513534
if hpost and hpost._handle then
514-
t = clone(t)
535+
t = t2 or clone(t); t2 = t;
515536
if t.httppost then t.httppost = hpost:handle() end
516537
if t[curl.OPT_HTTPPOST] then t[curl.OPT_HTTPPOST] = hpost:handle() end
517538
end
518539

540+
local easy = t.stream_depends or t[curl.OPT_STREAM_DEPENDS]
541+
if easy and easy._handle then
542+
t = t2 or clone(t); t2 = t;
543+
if t.stream_depends then t.stream_depends = easy:handle() end
544+
if t[curl.OPT_STREAM_DEPENDS] then t[curl.OPT_STREAM_DEPENDS] = easy:handle() end
545+
end
546+
547+
local easy = t.stream_depends_e or t[curl.OPT_STREAM_DEPENDS_E]
548+
if easy and easy._handle then
549+
t = t2 or clone(t); t2 = t;
550+
if t.stream_depends_e then t.stream_depends_e = easy:handle() end
551+
if t[curl.OPT_STREAM_DEPENDS_E] then t[curl.OPT_STREAM_DEPENDS_E] = easy:handle() end
552+
end
553+
519554
return setopt(self, t)
520555
end
521556

522-
if k == curl.OPT_HTTPPOST then
523-
return self:setopt_httppost(v)
557+
local setname = custom_setopt[k]
558+
if setname then
559+
return self[setname](self, v)
524560
end
525561

526562
return setopt(self, k, v)

test/test_curl.lua

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,93 @@ local fname = "./test.download"
2020

2121
local ENABLE = true
2222

23+
local _ENV = TEST_CASE'easy' if ENABLE then
24+
25+
local e1, e2
26+
function teardown()
27+
if e1 then e1:close() end
28+
if e2 then e2:close() end
29+
e1, e2 = nil
30+
end
31+
32+
if curl.OPT_STREAM_DEPENDS then
33+
34+
function test_easy_setopt_stream_depends_1()
35+
e1 = assert(scurl.easy())
36+
e2 = assert(scurl.easy())
37+
assert_pass(function()
38+
e1:setopt_stream_depends(e2)
39+
end)
40+
end
41+
42+
function test_easy_setopt_stream_depends_2()
43+
e1 = assert(scurl.easy())
44+
e2 = assert(scurl.easy())
45+
assert_pass(function()
46+
e1:setopt(curl.OPT_STREAM_DEPENDS, e2)
47+
end)
48+
end
49+
50+
function test_easy_setopt_stream_depends_3()
51+
e1 = assert(scurl.easy())
52+
e2 = assert(scurl.easy())
53+
assert_pass(function()
54+
e1:setopt{[curl.OPT_STREAM_DEPENDS] = e2}
55+
end)
56+
end
57+
58+
function test_easy_setopt_stream_depends_4()
59+
e1 = assert(scurl.easy())
60+
e2 = assert(scurl.easy())
61+
assert_pass(function()
62+
e1:setopt{stream_depends = e2}
63+
end)
64+
end
65+
66+
function test_easy_setopt_stream_depends_e_1()
67+
e1 = assert(scurl.easy())
68+
e2 = assert(scurl.easy())
69+
assert_pass(function()
70+
e1:setopt_stream_depends_e(e2)
71+
end)
72+
end
73+
74+
function test_easy_setopt_stream_depends_e_2()
75+
e1 = assert(scurl.easy())
76+
e2 = assert(scurl.easy())
77+
assert_pass(function()
78+
e1:setopt(curl.OPT_STREAM_DEPENDS_E, e2)
79+
end)
80+
end
81+
82+
function test_easy_setopt_stream_depends_e_3()
83+
e1 = assert(scurl.easy())
84+
e2 = assert(scurl.easy())
85+
assert_pass(function()
86+
e1:setopt{[curl.OPT_STREAM_DEPENDS_E] = e2}
87+
end)
88+
end
89+
90+
function test_easy_setopt_stream_depends_e_4()
91+
e1 = assert(scurl.easy())
92+
e2 = assert(scurl.easy())
93+
assert_pass(function()
94+
e1:setopt{stream_depends_e = e2}
95+
end)
96+
end
97+
98+
end
99+
100+
function test_easy_setopt_share()
101+
e1 = assert(scurl.easy())
102+
e2 = assert(scurl.share())
103+
assert_pass(function()
104+
e1:setopt_share(e2)
105+
end)
106+
end
107+
108+
end
109+
23110
local _ENV = TEST_CASE'multi_iterator' if ENABLE then
24111

25112
local url = "http://httpbin.org/get"

0 commit comments

Comments
 (0)