Skip to content

Commit

Permalink
Socket.request made a nonwritable Socket property set in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mokesmokes2 committed Feb 3, 2014
1 parent 461918b commit 3b8d786
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Server.prototype.handshake = function(transport, req){
sendErrorMessage(req.res, Server.errors.BAD_REQUEST);
return;
}
var socket = new Socket(id, this, transport);
var socket = new Socket(id, this, transport, req);
var self = this;

if (false !== this.cookie) {
Expand Down
18 changes: 7 additions & 11 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ module.exports = Socket;
* @api private
*/

function Socket (id, server, transport) {
function Socket (id, server, transport, req) {
this.id = id;
this.server = server;
this.upgraded = false;
this.readyState = 'opening';
this.writeBuffer = [];
this.packetsFn = [];
this.sentCallbackFn = [];
Object.defineProperty(this, 'request', {
value: req,
enumerable: true,
configurable: false,
writable: false
});

this.setTransport(transport);
this.onOpen();
Expand All @@ -36,16 +42,6 @@ function Socket (id, server, transport) {

Socket.prototype.__proto__ = EventEmitter.prototype;

/**
* Accessor for request that originated socket.
*
* @api public
*/

Socket.prototype.__defineGetter__('request', function () {
return this.transport.request;
});

/**
* Called upon transport considered open.
*
Expand Down
4 changes: 0 additions & 4 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ Transport.prototype.__proto__ = EventEmitter.prototype;

Transport.prototype.onRequest = function (req) {
debug('setting request');
if (undefined === this.req) {
debug('setting handshake request');
this.request = req;
}
this.req = req;
};

Expand Down
4 changes: 0 additions & 4 deletions lib/transports/polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ Polling.prototype.onPollRequest = function (req, res) {
res.writeHead(500);
} else {
debug('setting request');
if (undefined === this.req) {
debug('setting handshake request');
this.request = req;
}

this.req = req;
this.res = res;
Expand Down
4 changes: 4 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,12 +1360,16 @@ describe('server', function () {
}
}, 2);

expect(conn.request.query.transport).to.be('polling');

conn.on('message', function (msg) {
expect(conn.request.query).to.be.an('object');
lastReceived++;
expect(msg).to.eql(lastReceived);
});

conn.on('upgrade', function (to) {
expect(conn.request.query.transport).to.be('polling');
upgraded = true;
expect(to.name).to.be('websocket');
});
Expand Down

0 comments on commit 3b8d786

Please sign in to comment.