diff --git a/src/https.lua b/src/https.lua index bdfc17d..182877e 100644 --- a/src/https.lua +++ b/src/https.lua @@ -12,22 +12,18 @@ local ltn12 = require("ltn12") local http = require("socket.http") 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") - -_VERSION = "0.5" -_COPYRIGHT = "LuaSec 0.5 - Copyright (C) 2009-2014 PUC-Rio" - --- Default settings -PORT = 443 +-- +-- Module +-- +local _M = { + _VERSION = "0.5", + _COPYRIGHT = "LuaSec 0.5 - Copyright (C) 2009-2014 PUC-Rio", + PORT = 443, +} +-- TLS configuration local cfg = { protocol = "tlsv1", options = "all", @@ -40,7 +36,7 @@ local cfg = { -- Insert default HTTPS port. local function default_https_port(u) - return url.build(url.parse(u, {port = PORT})) + return url.build(url.parse(u, {port = _M.PORT})) end -- Convert an URL to a table according to Luasocket needs. @@ -113,7 +109,7 @@ end -- @param body optional (string) -- @return (string if url == string or 1), code, headers, status -- -function request(url, body) +local function request(url, body) local result_table = {} local stringrequest = type(url) == "string" if stringrequest then @@ -136,3 +132,11 @@ function request(url, body) end return res, code, headers, status end + +-------------------------------------------------------------------------------- +-- Export module +-- + +_M.request = request + +return _M diff --git a/src/ssl.lua b/src/ssl.lua index 1affb40..99036f5 100644 --- a/src/ssl.lua +++ b/src/ssl.lua @@ -8,14 +8,6 @@ local core = require("ssl.core") local context = require("ssl.context") 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, -- otherwise the C registry will be cleared. local registry = setmetatable({}, {__mode="k"}) @@ -37,7 +29,7 @@ end -- -- -- -function newcontext(cfg) +local function newcontext(cfg) local succ, msg, ctx -- Create the context ctx, msg = context.create(cfg.protocol) @@ -115,7 +107,7 @@ end -- -- -- -function wrap(sock, cfg) +local function wrap(sock, cfg) local ctx, msg if type(cfg) == "table" then ctx, msg = newcontext(cfg) @@ -170,3 +162,16 @@ end -- core.setmethod("info", info) +-------------------------------------------------------------------------------- +-- Export module +-- + +local _M = { + _VERSION = "0.5", + _COPYRIGHT = core.copyright(), + loadcertificate = x509.load, + newcontext = newcontext, + wrap = wrap, +} + +return _M