From 47fa9363ab5c2c49fc9b28e6a71c36dab1a1276c Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Mon, 15 Sep 2014 10:15:49 +0500 Subject: [PATCH 1/2] Update README.md [ci skip] --- README.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ce55362..fd7b9b1 100644 --- a/README.md +++ b/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() From e6c2ffce5c02455763856c87adafab3f783ef2dd Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Mon, 15 Sep 2014 10:57:33 +0500 Subject: [PATCH 2/2] Add. test to set/unset postfields --- test/test_easy.lua | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/test_easy.lua b/test/test_easy.lua index 0f38c18..27dd6ef 100644 --- a/test/test_easy.lua +++ b/test/test_easy.lua @@ -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