Created
August 16, 2016 16:22
-
-
Save Fingercomp/56268aa43201174f0852ba40d142e127 to your computer and use it in GitHub Desktop.
Luascket's https ⟷ OC http libraries compatibility layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ltn12 = require("ltn12") | |
local http = require("http") | |
local https = { | |
request = function(params) | |
local body = nil | |
if params.source then | |
body = "" | |
for chunk in params.source do | |
body = body .. chunk | |
end | |
end | |
local response, reason = http { | |
url = params.url, | |
method = params.method, | |
headers = params.headers, | |
body = body | |
} | |
if not response then | |
return false, reason | |
end | |
local success = true | |
local code, status, headers = response.response() | |
if params.sink then | |
local source = ltn12.source.string(response.read()) | |
ltn12.pump.all(source, params.sink) | |
end | |
return success, code, headers, status | |
end | |
} | |
return https |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment