Skip to content

Conversation

@FunkyAss
Copy link
Contributor

Add a table named "protocols" in the cURL module. The table is indexed with protocol names (as strings) and protocol values can be used with "bit-oriented" modules such as bit32 for lua 5.2 and lua BitOp for lua 5.1 and luajit.

Adds two functions to the easy handle metatable: setopt_protocols and setopt_redir_protocols. Both the functions accept a number as second argument. The number is a bitmask of protocols and can be be computed from "bit-oriented" modules and cURL.protocols table.

As an usage example:

-- require the right bit module: lua5.2 -> bit32, lua5.1 or luajit: lua BitOp local bit_op = _VERSION == "Lua 5.2" and "bit32" or "bit" local bit = require(bit_op) local curl = require "cURL" local protos = curl.protocols local easy = curl.easy_init() -- follow location headers (redirects) easy:setopt_followlocation(1) -- allow HTTP and HTTPS for requests easy:setopt_protocols(bit.bor(protos.HTTP, protos.HTTPS)) -- but follow redirect to http only easy:setopt_redir_protocols(protos.HTTP) -- http://github.com redirects to https://github.com easy:setopt_url("http://github.com") local success, err = pcall(easy.perform, easy) -- should fail with "https unsupported protocol" io.write("perform: ", tostring(success), '\n', err, '\n') 

Please note that libcurl <= 7.36 can't properly exclude protocols on-top-of-ssl, such as HTTPS, if the ssl-less protocol is among the allowed protocols. This is due a bug in libcurl, solved in curl/curl@710f14e

Should close #6

FunkyAss added 2 commits May 19, 2014 17:56
Add a table "protocols" in the module with protocol names as keys and CURLPROTO_* defines from curl.h as values. Those values are meant to be used with the bit32 module in lua 5.2 and with Lua BitOp in lua 5.1 and luajit. Exposing protocol values is the first step toward adding support for CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS from curl_easy_setopt. Signed-off-by: Davide "FunkyAss" Del Zompo <davide.delzompo@gmail.com>
The second argument of both the new functions, setopt_protocols and setopt_redir_protocols, is a number representing a bitmask of protocols (see libcurl documentation for curl_easy_setopt). Signed-off-by: Davide "FunkyAss" Del Zompo <davide.delzompo@gmail.com>
@msva
Copy link
Contributor

msva commented May 20, 2014

Those values are meant to be used with the bit32 module in lua 5.2 and with Lua BitOp in lua 5.1 and luajit.
AND luajit

Eerm? AFAIK LuaJIT has its own internal "bit" library.
// although, this remark has just cosmetic value. We just need to add it in the documentation, I guess.

msva added a commit that referenced this pull request May 20, 2014
Add support for CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS
@msva msva merged commit 93f3d0c into Lua-cURL:master May 20, 2014
@FunkyAss FunkyAss deleted the protos branch May 20, 2014 05:55
@FunkyAss
Copy link
Contributor Author

--- On 19/05/2014 - 19:39, Vadim A. Misbakh-Soloviov wrote:

Those values are meant to be used with the bit32 module in lua 5.2 and with Lua BitOp in lua 5.1 and luajit.
AND luajit

Eerm? AFAIK LuaJIT has its own internal "bit" library.
// although, this remark has just cosmetic value. We just need to add it in the documentation, I guess.


Reply to this email directly or view it on GitHub:
#9 (comment)
--- end quoted text ---

The luajit internal bit module is indeed lua BitOp.

I'm replying to this through my mail client; honestly, I don't know how
it will display or what it will do to the issue (if it will be reopened
or what): in any case, sorry about that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants