Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions src/lua/cURL/impl/cURL.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ local function make_iterator(self, perform)
end
end


-- name = <string>/<stream>/<file>/<buffer>/<content>
--
-- <stream> = {
Expand Down Expand Up @@ -504,23 +503,60 @@ function Easy:setopt_httppost(form)
return setopt_httppost(self, form:handle())
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 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)
if type(k) == 'table' then
local t = k

local t2
local hpost = t.httppost or t[curl.OPT_HTTPPOST]
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[curl.OPT_HTTPPOST] then t[curl.OPT_HTTPPOST] = hpost:handle() 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)
end

if k == curl.OPT_HTTPPOST then
return self:setopt_httppost(v)
local setname = custom_setopt[k]
if setname then
return self[setname](self, v)
end

return setopt(self, k, v)
Expand Down
87 changes: 87 additions & 0 deletions test/test_curl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,93 @@ local fname = "./test.download"

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 url = "http://httpbin.org/get"
Expand Down