From 953a363a59d4331148bb69ea7cd254a52784557e Mon Sep 17 00:00:00 2001 From: Bruno Silvestre Date: Mon, 2 Jul 2018 10:40:14 -0300 Subject: [PATCH] Add timeout to https module Glocal attribute https.TIMEOUT controls connection tiemout. Sample: https.TIMEOUT = 5 -- seconds https.request() --- src/https.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/https.lua b/src/https.lua index d1b708a..35371dd 100644 --- a/src/https.lua +++ b/src/https.lua @@ -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