Skip to content

Commit d69a044

Browse files
committed
Fix. cURL set stream depends options
1 parent fb8c79e commit d69a044

File tree

2 files changed

+125
-5
lines changed

2 files changed

+125
-5
lines changed

src/lua/cURL/impl/cURL.lua

Lines changed: 41 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,61 @@ 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 dummy = {}
522+
local custom_setopt = {
523+
[curl.OPT_HTTPPOST or true] = 'setopt_httppost';
524+
[curl.OPT_STREAM_DEPENDS or true] = 'setopt_stream_depends';
525+
[curl.OPT_STREAM_DEPENDS_E or true] = 'setopt_stream_depends_e';
526+
}
527+
custom_setopt[true] = nil
528+
508529
function Easy:setopt(k, v)
509530
if type(k) == 'table' then
510531
local t = k
511532

533+
local t2
512534
local hpost = t.httppost or t[curl.OPT_HTTPPOST]
513535
if hpost and hpost._handle then
514-
t = clone(t)
536+
t = t2 or clone(t); t2 = t;
515537
if t.httppost then t.httppost = hpost:handle() end
516538
if t[curl.OPT_HTTPPOST] then t[curl.OPT_HTTPPOST] = hpost:handle() end
517539
end
518540

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

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

526563
return setopt(self, k, v)

test/test_curl.lua

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,90 @@ local scurl = require "cURL.safe"
1818
local json = require "dkjson"
1919
local fname = "./test.download"
2020

21-
local ENABLE = true
21+
local ENABLE = false
22+
23+
local _ENV = TEST_CASE'easy' if true or 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+
function test_easy_setopt_stream_depends_1()
33+
e1 = assert(scurl.easy())
34+
e2 = assert(scurl.easy())
35+
assert_pass(function()
36+
e1:setopt_stream_depends(e2)
37+
end)
38+
end
39+
40+
function test_easy_setopt_stream_depends_2()
41+
e1 = assert(scurl.easy())
42+
e2 = assert(scurl.easy())
43+
assert_pass(function()
44+
e1:setopt(curl.OPT_STREAM_DEPENDS, e2)
45+
end)
46+
end
47+
48+
function test_easy_setopt_stream_depends_3()
49+
e1 = assert(scurl.easy())
50+
e2 = assert(scurl.easy())
51+
assert_pass(function()
52+
e1:setopt{[curl.OPT_STREAM_DEPENDS] = e2}
53+
end)
54+
end
55+
56+
function test_easy_setopt_stream_depends_4()
57+
e1 = assert(scurl.easy())
58+
e2 = assert(scurl.easy())
59+
assert_pass(function()
60+
e1:setopt{stream_depends = e2}
61+
end)
62+
end
63+
64+
function test_easy_setopt_stream_depends_e_1()
65+
e1 = assert(scurl.easy())
66+
e2 = assert(scurl.easy())
67+
assert_pass(function()
68+
e1:setopt_stream_depends_e(e2)
69+
end)
70+
end
71+
72+
function test_easy_setopt_stream_depends_e_2()
73+
e1 = assert(scurl.easy())
74+
e2 = assert(scurl.easy())
75+
assert_pass(function()
76+
e1:setopt(curl.OPT_STREAM_DEPENDS_E, e2)
77+
end)
78+
end
79+
80+
function test_easy_setopt_stream_depends_e_3()
81+
e1 = assert(scurl.easy())
82+
e2 = assert(scurl.easy())
83+
assert_pass(function()
84+
e1:setopt{[curl.OPT_STREAM_DEPENDS_E] = e2}
85+
end)
86+
end
87+
88+
function test_easy_setopt_stream_depends_e_4()
89+
e1 = assert(scurl.easy())
90+
e2 = assert(scurl.easy())
91+
assert_pass(function()
92+
e1:setopt{stream_depends_e = e2}
93+
end)
94+
end
95+
96+
function test_easy_setopt_share()
97+
e1 = assert(scurl.easy())
98+
e2 = assert(scurl.share())
99+
assert_pass(function()
100+
e1:setopt_share(e2)
101+
end)
102+
end
103+
104+
end
22105

23106
local _ENV = TEST_CASE'multi_iterator' if ENABLE then
24107

0 commit comments

Comments
 (0)