Merge pull request #66 from moteus/setopt_stream_depends

Fix. cURL set stream depends options
This commit is contained in:
Alexey Melnichuk 2016-04-17 12:08:32 +03:00
commit 3208536f83
2 changed files with 127 additions and 4 deletions

View File

@ -116,7 +116,6 @@ local function make_iterator(self, perform)
end end
end end
-- name = <string>/<stream>/<file>/<buffer>/<content> -- name = <string>/<stream>/<file>/<buffer>/<content>
-- --
-- <stream> = { -- <stream> = {
@ -504,23 +503,60 @@ function Easy:setopt_httppost(form)
return setopt_httppost(self, form:handle()) return setopt_httppost(self, form:handle())
end end
if curl.OPT_STREAM_DEPENDS then
local setopt_stream_depends = wrap_function("setopt_stream_depends")
function Easy:setopt_stream_depends(easy)
return setopt_stream_depends(self, easy:handle())
end
local setopt_stream_depends_e = wrap_function("setopt_stream_depends_e")
function Easy:setopt_stream_depends_e(easy)
return setopt_stream_depends_e(self, easy:handle())
end
end
local setopt = wrap_function("setopt") local setopt = wrap_function("setopt")
local custom_setopt = {
[curl.OPT_HTTPPOST or true] = 'setopt_httppost';
[curl.OPT_STREAM_DEPENDS or true] = 'setopt_stream_depends';
[curl.OPT_STREAM_DEPENDS_E or true] = 'setopt_stream_depends_e';
}
custom_setopt[true] = nil
function Easy:setopt(k, v) function Easy:setopt(k, v)
if type(k) == 'table' then if type(k) == 'table' then
local t = k local t = k
local t2
local hpost = t.httppost or t[curl.OPT_HTTPPOST] local hpost = t.httppost or t[curl.OPT_HTTPPOST]
if hpost and hpost._handle then if hpost and hpost._handle then
t = clone(t) t = t2 or clone(t); t2 = t;
if t.httppost then t.httppost = hpost:handle() end if t.httppost then t.httppost = hpost:handle() end
if t[curl.OPT_HTTPPOST] then t[curl.OPT_HTTPPOST] = hpost:handle() end if t[curl.OPT_HTTPPOST] then t[curl.OPT_HTTPPOST] = hpost:handle() end
end end
local easy = t.stream_depends or t[curl.OPT_STREAM_DEPENDS]
if easy and easy._handle then
t = t2 or clone(t); t2 = t;
if t.stream_depends then t.stream_depends = easy:handle() end
if t[curl.OPT_STREAM_DEPENDS] then t[curl.OPT_STREAM_DEPENDS] = easy:handle() end
end
local easy = t.stream_depends_e or t[curl.OPT_STREAM_DEPENDS_E]
if easy and easy._handle then
t = t2 or clone(t); t2 = t;
if t.stream_depends_e then t.stream_depends_e = easy:handle() end
if t[curl.OPT_STREAM_DEPENDS_E] then t[curl.OPT_STREAM_DEPENDS_E] = easy:handle() end
end
return setopt(self, t) return setopt(self, t)
end end
if k == curl.OPT_HTTPPOST then local setname = custom_setopt[k]
return self:setopt_httppost(v) if setname then
return self[setname](self, v)
end end
return setopt(self, k, v) return setopt(self, k, v)

View File

@ -20,6 +20,93 @@ local fname = "./test.download"
local ENABLE = true local ENABLE = true
local _ENV = TEST_CASE'easy' if ENABLE then
local e1, e2
function teardown()
if e1 then e1:close() end
if e2 then e2:close() end
e1, e2 = nil
end
if curl.OPT_STREAM_DEPENDS then
function test_easy_setopt_stream_depends_1()
e1 = assert(scurl.easy())
e2 = assert(scurl.easy())
assert_pass(function()
e1:setopt_stream_depends(e2)
end)
end
function test_easy_setopt_stream_depends_2()
e1 = assert(scurl.easy())
e2 = assert(scurl.easy())
assert_pass(function()
e1:setopt(curl.OPT_STREAM_DEPENDS, e2)
end)
end
function test_easy_setopt_stream_depends_3()
e1 = assert(scurl.easy())
e2 = assert(scurl.easy())
assert_pass(function()
e1:setopt{[curl.OPT_STREAM_DEPENDS] = e2}
end)
end
function test_easy_setopt_stream_depends_4()
e1 = assert(scurl.easy())
e2 = assert(scurl.easy())
assert_pass(function()
e1:setopt{stream_depends = e2}
end)
end
function test_easy_setopt_stream_depends_e_1()
e1 = assert(scurl.easy())
e2 = assert(scurl.easy())
assert_pass(function()
e1:setopt_stream_depends_e(e2)
end)
end
function test_easy_setopt_stream_depends_e_2()
e1 = assert(scurl.easy())
e2 = assert(scurl.easy())
assert_pass(function()
e1:setopt(curl.OPT_STREAM_DEPENDS_E, e2)
end)
end
function test_easy_setopt_stream_depends_e_3()
e1 = assert(scurl.easy())
e2 = assert(scurl.easy())
assert_pass(function()
e1:setopt{[curl.OPT_STREAM_DEPENDS_E] = e2}
end)
end
function test_easy_setopt_stream_depends_e_4()
e1 = assert(scurl.easy())
e2 = assert(scurl.easy())
assert_pass(function()
e1:setopt{stream_depends_e = e2}
end)
end
end
function test_easy_setopt_share()
e1 = assert(scurl.easy())
e2 = assert(scurl.share())
assert_pass(function()
e1:setopt_share(e2)
end)
end
end
local _ENV = TEST_CASE'multi_iterator' if ENABLE then local _ENV = TEST_CASE'multi_iterator' if ENABLE then
local url = "http://httpbin.org/get" local url = "http://httpbin.org/get"