Permalink
Browse files

fix bug when upgrade header has data

  • Loading branch information...
1 parent f00ec8e commit 1240a7a679772523a84262a8d27d017efc2c14dd @andrewrk committed Mar 14, 2013
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/WebSocket.js
View
@@ -518,19 +518,19 @@ function establishConnection(ReceiverClass, SenderClass, socket, upgradeHead) {
upgradeHead = null;
self._receiver.add(head);
}
- dataHandler = realHandler;
+ socket.removeListener('data', firstHandler);
+ socket.on('data', realHandler);
+ realHandler(data);
+ }
+ // subsequent packets are pushed straight to the receiver
+ function realHandler(data) {
+ if (self.readyState != WebSocket.OPEN) return;
if (data) {
self.bytesReceived += data.length;
self._receiver.add(data);
}
}
- // subsequent packets are pushed straight to the receiver
- function realHandler(data) {
- if (data) self.bytesReceived += data.length;
- self._receiver.add(data);
- }
- var dataHandler = firstHandler;
- socket.on('data', dataHandler);
+ socket.on('data', firstHandler);
// if data was passed along with the http upgrade,
// this will schedule a push of that on to the receiver.
// this has to be done on next tick, since the caller

0 comments on commit 1240a7a

Please sign in to comment.