diff --git a/lib/socket.js b/lib/socket.js index 9a96929728..4e97eb55dd 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -116,7 +116,7 @@ Socket.prototype.buildHandshake = function(query){ function buildQuery(){ var requestQuery = url.parse(self.request.url, true).query; //if socket-specific query exist, replace query strings in requestQuery - return Object.assign({}, query, requestQuery); + return Object.assign({}, requestQuery, query); } return { headers: this.request.headers, diff --git a/test/socket.io.js b/test/socket.io.js index 337f2ebd4a..6cc085b798 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -1621,8 +1621,25 @@ describe('socket.io', function(){ expect(s.handshake.query.key2).to.be('&=bb'); done(); }); + }); + + it('should see the query options sent in the Socket.IO handshake (specific to the given socket)', (done) => { + const srv = http(); + const sio = io(srv); + const socket = client(srv, '/namespace',{ query: { key1: 'a', key2: 'b' }}); // manager-specific query option + socket.query = { key2: 'c' }; // socket-specific query option + const success = () => { + sio.close(); + socket.close(); + done(); + } + sio.of('/namespace').on('connection', (s) => { + expect(s.handshake.query.key1).to.be('a'); // in the query params + expect(s.handshake.query.key2).to.be('c'); // in the Socket.IO handshake + success(); + }); }); it('should handle very large json', function(done){