Skip to content

Commit

Permalink
[fix] Fix undefined remoteAddress when using uws (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne authored Oct 11, 2017
1 parent 3c77780 commit 49362ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ function Socket (id, server, transport, req) {
this.request = req;

// Cache IP since it might not be in the req later
this.remoteAddress = req.connection.remoteAddress;
if (req.websocket && req.websocket._socket) {
this.remoteAddress = req.websocket._socket.remoteAddress;
} else {
this.remoteAddress = req.connection.remoteAddress;
}

this.checkIntervalTimer = null;
this.upgradeTimeoutTimer = null;
Expand Down
22 changes: 22 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2651,4 +2651,26 @@ describe('server', function () {
});
});
});

describe('remoteAddress', function () {
it('should be defined (polling)', function (done) {
var engine = listen({ transports: ['polling'] }, port => {
eioc('ws://localhost:%d'.s(port), { transports: ['polling'] });
engine.on('connection', socket => {
expect(socket.remoteAddress).to.be('::ffff:127.0.0.1');
done();
});
});
});

it('should be defined (ws)', function (done) {
var engine = listen({ transports: ['websocket'] }, port => {
eioc('ws://localhost:%d'.s(port), { transports: ['websocket'] });
engine.on('connection', socket => {
expect(socket.remoteAddress).to.be('::ffff:127.0.0.1');
done();
});
});
});
});
});

0 comments on commit 49362ab

Please sign in to comment.