Don't do so many writes.
This commit is contained in:
@@ -16,11 +16,11 @@ var instance = {
|
||||
handshakeResponse: function() {
|
||||
var stream = this._stream;
|
||||
try {
|
||||
stream.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n');
|
||||
stream.write('Upgrade: WebSocket\r\n');
|
||||
stream.write('Connection: Upgrade\r\n');
|
||||
stream.write('WebSocket-Origin: ' + this._socket.request.headers.origin + '\r\n');
|
||||
stream.write('WebSocket-Location: ' + this._socket.url + '\r\n\r\n');
|
||||
stream.write( 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
|
||||
'Upgrade: WebSocket\r\n' +
|
||||
'Connection: Upgrade\r\n' +
|
||||
'WebSocket-Origin: ' + this._socket.request.headers.origin + '\r\n' +
|
||||
'WebSocket-Location: ' + this._socket.url + '\r\n\r\n');
|
||||
} catch (e) {
|
||||
// socket closed while writing
|
||||
// no handshake sent; client will stop using WebSocket
|
||||
|
||||
@@ -43,11 +43,13 @@ Draft76Parser.prototype.handshakeResponse = function(head) {
|
||||
MD5.update(head.toString('binary'));
|
||||
|
||||
try {
|
||||
stream.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n', 'binary');
|
||||
stream.write('Upgrade: WebSocket\r\n', 'binary');
|
||||
stream.write('Connection: Upgrade\r\n', 'binary');
|
||||
stream.write('Sec-WebSocket-Origin: ' + request.headers.origin + '\r\n', 'binary');
|
||||
stream.write('Sec-WebSocket-Location: ' + this._socket.url + '\r\n\r\n', 'binary');
|
||||
stream.write( 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
|
||||
'Upgrade: WebSocket\r\n' +
|
||||
'Connection: Upgrade\r\n' +
|
||||
'Sec-WebSocket-Origin: ' + request.headers.origin + '\r\n' +
|
||||
'Sec-WebSocket-Location: ' + this._socket.url + '\r\n\r\n',
|
||||
'binary');
|
||||
|
||||
stream.write(MD5.digest('binary'), 'binary');
|
||||
} catch (e) {
|
||||
// socket closed while writing
|
||||
|
||||
@@ -43,13 +43,12 @@ var Handshake = function(uri, stream) {
|
||||
Handshake.prototype.requestData = function() {
|
||||
var stream = this._stream, u = this._uri;
|
||||
try {
|
||||
stream.write('GET ' + u.pathname + (u.search || '') + ' HTTP/1.1\r\n');
|
||||
stream.write('Host: ' + u.hostname + (u.port ? ':' + u.port : '') + '\r\n');
|
||||
stream.write('Upgrade: websocket\r\n');
|
||||
stream.write('Connection: Upgrade\r\n');
|
||||
stream.write('Sec-WebSocket-Key: ' + this._key + '\r\n');
|
||||
stream.write('Sec-WebSocket-Version: 8\r\n');
|
||||
stream.write('\r\n');
|
||||
stream.write( 'GET ' + u.pathname + (u.search || '') + ' HTTP/1.1\r\n' +
|
||||
'Host: ' + u.hostname + (u.port ? ':' + u.port : '') + '\r\n' +
|
||||
'Upgrade: websocket\r\n' +
|
||||
'Connection: Upgrade\r\n' +
|
||||
'Sec-WebSocket-Key: ' + this._key + '\r\n' +
|
||||
'Sec-WebSocket-Version: 8\r\n\r\n');
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
@@ -136,10 +135,10 @@ var instance = {
|
||||
|
||||
var stream = this._stream;
|
||||
try {
|
||||
stream.write('HTTP/1.1 101 Switching Protocols\r\n');
|
||||
stream.write('Upgrade: websocket\r\n');
|
||||
stream.write('Connection: Upgrade\r\n');
|
||||
stream.write('Sec-WebSocket-Accept: ' + accept + '\r\n\r\n');
|
||||
stream.write( 'HTTP/1.1 101 Switching Protocols\r\n' +
|
||||
'Upgrade: websocket\r\n' +
|
||||
'Connection: Upgrade\r\n' +
|
||||
'Sec-WebSocket-Accept: ' + accept + '\r\n\r\n');
|
||||
} catch (e) {
|
||||
// socket closed while writing
|
||||
// no handshake sent; client will stop using WebSocket
|
||||
|
||||
Reference in New Issue
Block a user