-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1460 from simov/local-address
localAddress or proxy config is lost when redirecting
- Loading branch information
Showing
2 changed files
with
30 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,49 @@ | ||
'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) | ||
t.end() | ||
}) | ||
}) | ||
|
||
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() | ||
}) | ||
}) |