From d7ed0a5710a19ea340e8964c7aed2e634d833c41 Mon Sep 17 00:00:00 2001 From: mdemo Date: Sun, 8 Feb 2015 12:24:38 +0800 Subject: [PATCH 1/8] Add node.js 0.12 and io.js to travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0988483f3..f0da7e686 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: node_js node_js: - "0.8" - "0.10" + - "0.12" + - "io.js" before_install: npm install -g npm@~1.4.6 after_script: ./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape tests/test-*.js --report lcovonly && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js --verbose webhooks: From 237e80fe076680669da7f1d3b42b9cba19e91e1c Mon Sep 17 00:00:00 2001 From: 0x4139 <0x4139@gmail.com> Date: Thu, 19 Feb 2015 13:02:35 +0200 Subject: [PATCH 2/8] fixes the redirect initialization of an object when localAddress or proxy is lost due to the reinitialization without parameters of the request object --- lib/redirect.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/redirect.js b/lib/redirect.js index 2d9a9d518..ff6c32fda 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -138,7 +138,10 @@ Redirect.prototype.onResponse = function (response) { request.emit('redirect') - request.init() + request.init({ + localAddress:self.localAddress, + proxy:self.proxy + }) return true } From 93affc4acc2285dd6ba0c91306df21ae51580271 Mon Sep 17 00:00:00 2001 From: 0x4139 <0x4139@gmail.com> Date: Thu, 19 Feb 2015 15:08:35 +0200 Subject: [PATCH 3/8] bind to localAddress on redirect, and the afferent test --- lib/redirect.js | 6 ++-- tests/test-localAddress.js | 66 ++++++++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index ff6c32fda..b086c1992 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -138,9 +138,9 @@ Redirect.prototype.onResponse = function (response) { request.emit('redirect') - request.init({ - localAddress:self.localAddress, - proxy:self.proxy + request.init({ + localAddress:request.localAddress, + proxy:request.proxy }) return true diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 4445001d5..648f422df 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -1,27 +1,51 @@ 'use strict' - var request = require('../index') - , tape = require('tape') + , tape = require('tape') + +tape('bind to invalid address', function (t) { + request.get({ + uri: 'http://www.google.com', + localAddress: '1.2.3.4' + }, function (err, res) { + t.notEqual(err, null) + t.equal(err.message, 'bind EADDRNOTAVAIL') + t.equal(res, undefined) + t.end() + }) +}) -tape('bind to invalid address', function(t) { - request.get({ - uri: 'http://www.google.com', - localAddress: '1.2.3.4' - }, function(err, res) { - t.notEqual(err, null) - t.equal(err.message, 'bind EADDRNOTAVAIL') - t.equal(res, undefined) - t.end() - }) +tape('bind to local address', function (t) { + request.get({ + uri: 'http://www.google.com', + localAddress: '127.0.0.1' + }, function (err, res) { + t.notEqual(err, null) + t.equal(res, undefined) + t.end() + }) }) -tape('bind to local address', function(t) { - request.get({ - uri: 'http://www.google.com', - localAddress: '127.0.0.1' - }, function(err, res) { - t.notEqual(err, null) - t.equal(res, undefined) - t.end() - }) +tape('bind to local address on redirect', function (t) { + var os = require('os') + var localInterfaces = os.networkInterfaces() + var localIPS=[] + Object.keys(localInterfaces).forEach(function (ifname) { + localInterfaces[ifname].forEach(function (iface) { + if ('IPv4' !== iface.family || iface.internal !== false) { + // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses + return; + } + localIPS.push(iface.address); + }); + }); + request.get({ + uri: 'http://google.com', //redirects to 'http://google.com' + localAddress: localIPS[0] + }, function (err, res) { + t.equal(err, null) + res.body = ""; + console.log(res.request.method); + t.equal(res.request.localAddress, localIPS[0]) + t.end() + }) }) From 92be4017f436b32634e79c68a67962e773c27534 Mon Sep 17 00:00:00 2001 From: 0x4139 <0x4139@gmail.com> Date: Thu, 19 Feb 2015 15:10:24 +0200 Subject: [PATCH 4/8] cleans up test-localAddress --- tests/test-localAddress.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 648f422df..325b2985a 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -43,8 +43,6 @@ tape('bind to local address on redirect', function (t) { localAddress: localIPS[0] }, function (err, res) { t.equal(err, null) - res.body = ""; - console.log(res.request.method); t.equal(res.request.localAddress, localIPS[0]) t.end() }) From 52316f7d4e0aff3da49235084108002b74b41b24 Mon Sep 17 00:00:00 2001 From: Ollie Relph Date: Fri, 20 Feb 2015 12:57:01 +0000 Subject: [PATCH 5/8] Set cipher to one that matches the certificates used for testing strictSSL --- tests/server.js | 2 +- tests/test-https.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/server.js b/tests/server.js index e6f398dee..c8556f5e8 100644 --- a/tests/server.js +++ b/tests/server.js @@ -34,7 +34,7 @@ exports.createSSLServer = function(port, opts) { } for (i in options) { - if (i !== 'requestCert' && i !== 'rejectUnauthorized') { + if (i !== 'requestCert' && i !== 'rejectUnauthorized' && i !== 'ciphers') { options[i] = fs.readFileSync(options[i]) } } diff --git a/tests/test-https.js b/tests/test-https.js index 04b1aa423..396a73d83 100644 --- a/tests/test-https.js +++ b/tests/test-https.js @@ -13,6 +13,7 @@ var s = server.createSSLServer() , caFile = path.resolve(__dirname, 'ssl/ca/ca.crt') , ca = fs.readFileSync(caFile) , opts = { + ciphers: 'AES256-SHA', key: path.resolve(__dirname, 'ssl/ca/server.key'), cert: path.resolve(__dirname, 'ssl/ca/server.crt') } From 7759f6006ccfa5f0bf4182c50942f381c4a840d6 Mon Sep 17 00:00:00 2001 From: 0x4139 <0x4139@gmail.com> Date: Wed, 25 Feb 2015 15:51:27 +0200 Subject: [PATCH 6/8] fixed linting --- tests/test-localAddress.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 325b2985a..9d65dd157 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -28,16 +28,16 @@ tape('bind to local address', function (t) { tape('bind to local address on redirect', function (t) { var os = require('os') var localInterfaces = os.networkInterfaces() - var localIPS=[] + var localIPS = [] Object.keys(localInterfaces).forEach(function (ifname) { localInterfaces[ifname].forEach(function (iface) { - if ('IPv4' !== iface.family || iface.internal !== false) { + if (iface.family !== 'IPv4' || iface.internal !== false) { // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses - return; + return } - localIPS.push(iface.address); - }); - }); + localIPS.push(iface.address) + }) + }) request.get({ uri: 'http://google.com', //redirects to 'http://google.com' localAddress: localIPS[0] From 1f6fbd57b8e2be0071e9771846790dda137ebb9a Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 26 Feb 2015 08:23:49 +0200 Subject: [PATCH 7/8] Fix indentation and localAddress check in init --- lib/redirect.js | 5 +-- request.js | 4 ++- tests/test-localAddress.js | 74 +++++++++++++++++++------------------- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/lib/redirect.js b/lib/redirect.js index b086c1992..2d9a9d518 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -138,10 +138,7 @@ Redirect.prototype.onResponse = function (response) { request.emit('redirect') - request.init({ - localAddress:request.localAddress, - proxy:request.proxy - }) + request.init() return true } diff --git a/request.js b/request.js index 6f1305a41..c6507620c 100644 --- a/request.js +++ b/request.js @@ -322,7 +322,9 @@ Request.prototype.init = function (options) { if (!self.method) { self.method = options.method || 'GET' } - self.localAddress = options.localAddress + if (!self.localAddress) { + self.localAddress = options.localAddress + } if (!self.qsLib) { self.qsLib = (options.useQuerystring ? querystring : qs) diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 9d65dd157..faa52fae2 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -1,49 +1,49 @@ 'use strict' var request = require('../index') - , tape = require('tape') + , tape = require('tape') tape('bind to invalid address', function (t) { - request.get({ - uri: 'http://www.google.com', - localAddress: '1.2.3.4' - }, function (err, res) { - t.notEqual(err, null) - t.equal(err.message, 'bind EADDRNOTAVAIL') - t.equal(res, undefined) - t.end() - }) + request.get({ + uri: 'http://www.google.com', + localAddress: '1.2.3.4' + }, function (err, res) { + t.notEqual(err, null) + t.equal(err.message, 'bind EADDRNOTAVAIL') + t.equal(res, undefined) + t.end() + }) }) tape('bind to local address', function (t) { - request.get({ - uri: 'http://www.google.com', - localAddress: '127.0.0.1' - }, function (err, res) { - t.notEqual(err, null) - t.equal(res, undefined) - t.end() - }) + request.get({ + uri: 'http://www.google.com', + localAddress: '127.0.0.1' + }, function (err, res) { + t.notEqual(err, null) + t.equal(res, undefined) + t.end() + }) }) tape('bind to local address on redirect', function (t) { - var os = require('os') - var localInterfaces = os.networkInterfaces() - var localIPS = [] - Object.keys(localInterfaces).forEach(function (ifname) { - localInterfaces[ifname].forEach(function (iface) { - if (iface.family !== 'IPv4' || iface.internal !== false) { - // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses - return - } - localIPS.push(iface.address) - }) - }) - request.get({ - uri: 'http://google.com', //redirects to 'http://google.com' - localAddress: localIPS[0] - }, function (err, res) { - t.equal(err, null) - t.equal(res.request.localAddress, localIPS[0]) - t.end() + var os = require('os') + var localInterfaces = os.networkInterfaces() + var localIPS = [] + Object.keys(localInterfaces).forEach(function (ifname) { + localInterfaces[ifname].forEach(function (iface) { + if (iface.family !== 'IPv4' || iface.internal !== false) { + // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses + return + } + localIPS.push(iface.address) }) + }) + request.get({ + uri: 'http://google.com', //redirects to 'http://google.com' + localAddress: localIPS[0] + }, function (err, res) { + t.equal(err, null) + t.equal(res.request.localAddress, localIPS[0]) + t.end() + }) }) From aaf208ea83f19d6dee232999415540ec0913dfbe Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Sun, 1 Mar 2015 23:00:36 -0500 Subject: [PATCH 8/8] Allow build failures on Node 0.12 and io.js --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 368e1ee92..98472f761 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ node_js: - "0.10" - "0.12" - "io.js" +matrix: + allow_failures: + - node_js: "0.12" + - node_js: "io.js" after_script: ./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape tests/test-*.js --report lcovonly && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js --verbose webhooks: urls: https://webhooks.gitter.im/e/237280ed4796c19cc626