Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: Supply host argument in the Socket lookup event callback. #5598

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/net.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ Not applicable to UNIX sockets.
* `err` {Error|Null} The error object. See [`dns.lookup()`][].
* `address` {String} The IP address.
* `family` {String|Null} The address type. See [`dns.lookup()`][].
* `host` {String} The hostname.

### Event: 'timeout'

Expand Down
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ function lookupAndConnect(self, options) {
self._host = host;
var lookup = options.lookup || dns.lookup;
lookup(host, dnsopts, function(err, ip, addressType) {
self.emit('lookup', err, ip, addressType);
self.emit('lookup', err, ip, addressType, host);

// It's possible we were destroyed while looking this up.
// XXX it would be great if we could cancel the promise returned by
Expand Down
14 changes: 8 additions & 6 deletions test/parallel/test-net-dns-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ var server = net.createServer(function(client) {
});

server.listen(common.PORT, '127.0.0.1', function() {
net.connect(common.PORT, 'localhost').on('lookup', function(err, ip, type) {
assert.equal(err, null);
assert.equal(ip, '127.0.0.1');
assert.equal(type, '4');
ok = true;
});
net.connect(common.PORT, 'localhost')
.on('lookup', function(err, ip, type, host) {
assert.equal(err, null);
assert.equal(ip, '127.0.0.1');
assert.equal(type, '4');
assert.equal(host, 'localhost');
ok = true;
});
});

process.on('exit', function() {
Expand Down