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
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Lua-cURLv2 binding has several problems:
* it has memory leak when send multipart/formdata
* it does not save string for curl options that may result crush in libcurl
* there no way to get result for operations in multi interface (e.g. if one of easy operation fail you can not get result code/error message)
* you can not use multi interface for upload operation (?)
* you can not use your own callback function to perform operation with multi interface
* you can not pass your context to callback functions

Expand Down Expand Up @@ -62,7 +61,7 @@ curl.easy()
curl.easy()
:setopt_url('http://posttestserver.com/post.php')
:setopt_writefunction(io.write)
:setopt_httppost(curl.form() -- lcurl guarantee that form will be alive
:setopt_httppost(curl.form() -- Lua-cURL guarantee that form will be alive
:add_content("test_content", "some data", {
"MyHeader: SomeValue"
})
Expand Down Expand Up @@ -101,16 +100,12 @@ curl.easy()
-- Multi FTP Upload

-- We get error E_LOGIN_DENIED for this operation
e1 = curl.easy()
:setopt_url("ftp://moteus:999999@127.0.0.1/test1.dat")
:setopt_upload(true)
e1 = curl.easy{url = "ftp://moteus:999999@127.0.0.1/test1.dat", upload = true}
:setopt_readfunction(
function(t) return table.remove(t) end, {"1111", "2222"}
)

e2 = curl.easy()
:setopt_url("ftp://moteus:123456@127.0.0.1/test2.dat")
:setopt_upload(true)
e2 = curl.easy{url = "ftp://moteus:123456@127.0.0.1/test2.dat", upload = true}
:setopt_readfunction(get_bin_by(("e"):rep(1000), 5))

m = curl.multi()
Expand Down
55 changes: 55 additions & 0 deletions test/test_easy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,61 @@ function test_reset()
assert(not pfrom.value)
end

end

local _ENV = TEST_CASE'setopt_postfields' if ENABLE then

local c

function teardown()
if c then c:close() end
c = nil
end

function test()

do local fields = {}
for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end
fields = table.concat(fields, '&')
c = assert(curl.easy{
url = "http://httpbin.org/post",
postfields = fields,
writefunction = function()end,
})
end

-- call gc to try clear `fields` string
for i = 1, 4 do collectgarbage"collect" end

c:perform()
end

function test_unset()
local pfields

do local fields = {}
for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end
fields = table.concat(fields, '&')
c = assert(curl.easy{
url = "http://httpbin.org/post",
postfields = fields,
writefunction = function()end,
})
pfields = weak_ptr(fields)
end

-- call gc to try clear `fields` string
for i = 1, 4 do collectgarbage"collect" end
assert_string(pfields.value)

assert_equal(c, c:unsetopt_postfields())

-- @todo check internal storage because gc really do not clear `weak` string
-- for i = 1, 4 do collectgarbage"collect" end
-- assert_nil(pfields.value)

-- c:perform()
end

end

Expand Down