diff --git a/lib/client.js b/lib/client.js index 60a94c2..eae33db 100644 --- a/lib/client.js +++ b/lib/client.js @@ -18,7 +18,8 @@ let client = (connection) => { rejectUnauthorized: connection.rejectUnauthorized, secureProtocol: connection.secureProtocol, servername: connection.servername, - headers: {'Content-Type': 'application/json', host: connection.host} + headers: {'Content-Type': 'application/json', host: connection.host}, + timeout: connection.timeout || 10000 }; if(connection.user && connection.pass){ @@ -42,6 +43,13 @@ let client = (connection) => { let data = ""; + req.on('socket', function (socket) { + socket.setTimeout(options.timeout); + socket.on('timeout', function () { + req.abort(); + }); + }); + req.on('error', (e) => { cb(e); });