Merge pull request #30 from moteus/master
Add. test to set/unset postfields
This commit is contained in:
commit
4817dad2c7
11
README.md
11
README.md
@ -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
|
||||
|
||||
@ -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"
|
||||
})
|
||||
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user