diff --git a/.travis.yml b/.travis.yml index b67e2afba..98472f761 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,12 @@ language: node_js 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 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/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') } diff --git a/tests/test-localAddress.js b/tests/test-localAddress.js index 1a1723b42..ea3a4ce7c 100644 --- a/tests/test-localAddress.js +++ b/tests/test-localAddress.js @@ -1,13 +1,12 @@ 'use strict' - var request = require('../index') , tape = require('tape') -tape('bind to invalid address', function(t) { +tape('bind to invalid address', function (t) { request.get({ uri: 'http://www.google.com', localAddress: '1.2.3.4' - }, function(err, res) { + }, function (err, res) { t.notEqual(err, null) t.equal(true, /bind EADDRNOTAVAIL/.test(err.message)) t.equal(res, undefined) @@ -15,13 +14,36 @@ tape('bind to invalid address', function(t) { }) }) -tape('bind to local address', function(t) { +tape('bind to local address', function (t) { request.get({ uri: 'http://www.google.com', localAddress: '127.0.0.1' - }, function(err, res) { + }, 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() + }) +})