Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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