msva/lua-curl — pull request #9 by FunkyAss (2014-05-19 17:08:46+00:00)
Title: Add support for CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS

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 bagder/curl@710f14edba4491a4ac9222a7e3103b51fd30dbe0

Should close #6