Stop using module().

This commit is contained in:
Bruno Silvestre 2015-02-06 18:07:29 -02:00
parent 97b1974039
commit 356e03a64d
2 changed files with 35 additions and 26 deletions

View File

@ -12,22 +12,18 @@ local ltn12 = require("ltn12")
local http = require("socket.http") local http = require("socket.http")
local url = require("socket.url") local url = require("socket.url")
local table = require("table")
local string = require("string")
local try = socket.try local try = socket.try
local type = type
local pairs = pairs
local getmetatable = getmetatable
module("ssl.https") --
-- Module
_VERSION = "0.5" --
_COPYRIGHT = "LuaSec 0.5 - Copyright (C) 2009-2014 PUC-Rio" local _M = {
_VERSION = "0.5",
-- Default settings _COPYRIGHT = "LuaSec 0.5 - Copyright (C) 2009-2014 PUC-Rio",
PORT = 443 PORT = 443,
}
-- TLS configuration
local cfg = { local cfg = {
protocol = "tlsv1", protocol = "tlsv1",
options = "all", options = "all",
@ -40,7 +36,7 @@ local cfg = {
-- Insert default HTTPS port. -- Insert default HTTPS port.
local function default_https_port(u) local function default_https_port(u)
return url.build(url.parse(u, {port = PORT})) return url.build(url.parse(u, {port = _M.PORT}))
end end
-- Convert an URL to a table according to Luasocket needs. -- Convert an URL to a table according to Luasocket needs.
@ -113,7 +109,7 @@ end
-- @param body optional (string) -- @param body optional (string)
-- @return (string if url == string or 1), code, headers, status -- @return (string if url == string or 1), code, headers, status
-- --
function request(url, body) local function request(url, body)
local result_table = {} local result_table = {}
local stringrequest = type(url) == "string" local stringrequest = type(url) == "string"
if stringrequest then if stringrequest then
@ -136,3 +132,11 @@ function request(url, body)
end end
return res, code, headers, status return res, code, headers, status
end end
--------------------------------------------------------------------------------
-- Export module
--
_M.request = request
return _M

View File

@ -8,14 +8,6 @@ local core = require("ssl.core")
local context = require("ssl.context") local context = require("ssl.context")
local x509 = require("ssl.x509") local x509 = require("ssl.x509")
module("ssl", package.seeall)
_VERSION = "0.5"
_COPYRIGHT = core.copyright()
-- Export
loadcertificate = x509.load
-- We must prevent the contexts to be collected before the connections, -- We must prevent the contexts to be collected before the connections,
-- otherwise the C registry will be cleared. -- otherwise the C registry will be cleared.
local registry = setmetatable({}, {__mode="k"}) local registry = setmetatable({}, {__mode="k"})
@ -37,7 +29,7 @@ end
-- --
-- --
-- --
function newcontext(cfg) local function newcontext(cfg)
local succ, msg, ctx local succ, msg, ctx
-- Create the context -- Create the context
ctx, msg = context.create(cfg.protocol) ctx, msg = context.create(cfg.protocol)
@ -115,7 +107,7 @@ end
-- --
-- --
-- --
function wrap(sock, cfg) local function wrap(sock, cfg)
local ctx, msg local ctx, msg
if type(cfg) == "table" then if type(cfg) == "table" then
ctx, msg = newcontext(cfg) ctx, msg = newcontext(cfg)
@ -170,3 +162,16 @@ end
-- --
core.setmethod("info", info) core.setmethod("info", info)
--------------------------------------------------------------------------------
-- Export module
--
local _M = {
_VERSION = "0.5",
_COPYRIGHT = core.copyright(),
loadcertificate = x509.load,
newcontext = newcontext,
wrap = wrap,
}
return _M