Add timeout to https module

Glocal attribute https.TIMEOUT controls connection tiemout.

Sample:
  https.TIMEOUT = 5  -- seconds
  https.request()
This commit is contained in:
Bruno Silvestre 2018-07-02 10:40:14 -03:00
parent 28e247dbc5
commit 953a363a59

View File

@ -21,6 +21,7 @@ local _M = {
_VERSION = "0.7",
_COPYRIGHT = "LuaSec 0.7 - Copyright (C) 2009-2018 PUC-Rio",
PORT = 443,
TIMEOUT = 60
}
-- TLS configuration
@ -83,13 +84,14 @@ local function tcp(params)
conn.sock = try(socket.tcp())
local st = getmetatable(conn.sock).__index.settimeout
function conn:settimeout(...)
return st(self.sock, ...)
return st(self.sock, _M.TIMEOUT)
end
-- Replace TCP's connection function
function conn:connect(host, port)
try(self.sock:connect(host, port))
self.sock = try(ssl.wrap(self.sock, params))
self.sock:sni(host)
self.sock:settimeout(_M.TIMEOUT)
try(self.sock:dohandshake())
reg(self, getmetatable(self.sock))
return 1