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

fix undefined remoteAddress when using uws #533

Merged
merged 2 commits into from
Oct 11, 2017
Merged
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
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();
});
});
});
});
});