From 172a3d40e07ebf5b9381f605be27b34c9cb0140a Mon Sep 17 00:00:00 2001 From: Pedro Alan Date: Tue, 29 Oct 2019 10:35:28 -0300 Subject: [PATCH 1/3] Fixed timeout not being respected --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1763415..5922de2 100644 --- a/index.js +++ b/index.js @@ -64,12 +64,15 @@ function get(url, timeout, port, protocol, detailed) { protocol = protocol || 'https:'; var options = getOptions(url, port, protocol); + + if (timeout) + options['timeout'] = timeout; return new Promise(function(resolve, reject) { var req = handleRequest(options, detailed, resolve, reject); if (timeout) { - req.setTimeout(timeout, function() { + req.on('timeout', ()=> { reject({ message: 'Request timed out.' }); req.abort(); }); From 5d2af6684282a80d37ebf897f1da92ccaf7544b0 Mon Sep 17 00:00:00 2001 From: Pedro Alan Date: Tue, 29 Oct 2019 10:37:23 -0300 Subject: [PATCH 2/3] Added unreachable ip timeout test --- test/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/index.js b/test/index.js index 5fd189f..ec4d47d 100644 --- a/test/index.js +++ b/test/index.js @@ -145,4 +145,16 @@ describe('Live getSSLCertificate.get()', function() { done(); }); }); + + it('should timeout at expected time', function(done) { + const startTime = new Date(); + getSSLCertificate + .get('59.96.120.246', 1400) // Not sure which unreachable IP to put in here + .catch(function(error) { + const endTime = new Date(); + expect(error.message).to.be.equal('Request timed out.'); + expect(endTime - startTime).to.be.below(1500); // 100 ms of tolerance + done(); + }); + }); }); From 54161b26ffbc9062e1f1db43024ab49f554f473f Mon Sep 17 00:00:00 2001 From: Pedro Alan Date: Tue, 4 Feb 2020 14:54:16 -0300 Subject: [PATCH 3/3] Fixed spacing and conditional block without braces --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5922de2..8fbec72 100644 --- a/index.js +++ b/index.js @@ -65,14 +65,15 @@ function get(url, timeout, port, protocol, detailed) { var options = getOptions(url, port, protocol); - if (timeout) + if (timeout) { options['timeout'] = timeout; + } return new Promise(function(resolve, reject) { var req = handleRequest(options, detailed, resolve, reject); if (timeout) { - req.on('timeout', ()=> { + req.on('timeout', () => { reject({ message: 'Request timed out.' }); req.abort(); });