Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Proper support for draft 76

  • Loading branch information...
commit 8bf30afda2af885955618c77ccfcc961869c4c2b 1 parent b971a18
@rauchg rauchg authored
Showing with 18 additions and 7 deletions.
  1. +18 −7 lib/socket.io/transports/websocket.js
View
25 lib/socket.io/transports/websocket.js
@@ -32,10 +32,10 @@ exports.websocket = Client.extend({
'HTTP/1.1 101 WebSocket Protocol Handshake',
'Upgrade: WebSocket',
'Connection: Upgrade',
- 'Sec-WebSocket-Origin: ' + origin ? origin : "null",
+ 'Sec-WebSocket-Origin: ' + (origin || 'null'),
'Sec-WebSocket-Location: ws://' + this.request.headers.host + this.request.url
];
-
+
if ('sec-websocket-protocol' in this.request.headers) {
headers.push('Sec-WebSocket-Protocol: ' + this.request.headers['sec-websocket-protocol']);
}
@@ -49,8 +49,12 @@ exports.websocket = Client.extend({
'WebSocket-Origin: ' + this.request.headers.origin,
'WebSocket-Location: ws://' + this.request.headers.host + this.request.url
];
-
- this.connection.write(headers.concat('', '').join('\r\n'));
+
+ try {
+ this.connection.write(headers.concat('', '').join('\r\n'));
+ } catch(e){
+ this._onClose();
+ }
}
this.connection.addListener('end', function(){self._onClose();});
@@ -68,7 +72,7 @@ exports.websocket = Client.extend({
_handle: function(data){
var chunk, chunks, chunk_count;
this.data += data;
- chunks = this.data.split(this.draft == 76 ? '\ufffd' : '\u00ff');
+ chunks = this.data.split('\ufffd');
chunk_count = chunks.length - 1;
for (var i = 0; i < chunk_count; i++) {
chunk = chunks[i];
@@ -85,7 +89,8 @@ exports.websocket = Client.extend({
// http://www.whatwg.org/specs/web-apps/current-work/complete/network.html#opening-handshake
_proveReception: function(headers){
var k1 = this.request.headers['sec-websocket-key1'],
- k2 = this.request.headers['sec-websocket-key2'];
+ k2 = this.request.headers['sec-websocket-key2'];
+
if (k1 && k2) {
var md5 = crypto.createHash('md5');
@@ -109,8 +114,14 @@ exports.websocket = Client.extend({
});
md5.update(this.upgradeHead.toString('binary'));
- this.connection.write(headers.concat('', '').join('\r\n') + md5.digest('binary'), 'binary');
+
+ try {
+ this.connection.write(headers.concat('', '').join('\r\n') + md5.digest('binary'), 'binary');
+ } catch(e){
+ this._onClose();
+ }
}
+
return true;
},
Please sign in to comment.
Something went wrong with that request. Please try again.