Skip to content

Instantly share code, notes, and snippets.

@Fingercomp
Created August 16, 2016 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fingercomp/56268aa43201174f0852ba40d142e127 to your computer and use it in GitHub Desktop.
Save Fingercomp/56268aa43201174f0852ba40d142e127 to your computer and use it in GitHub Desktop.
Luascket's https ⟷ OC http libraries compatibility layer
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