Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 19da8de414 | |||
| 85ddb3f3dc | |||
| 7e2461e153 | |||
| ca3571f103 | |||
| 27f8f9a0f2 |
@@ -0,0 +1,21 @@
|
||||
defaults
|
||||
mode http
|
||||
timeout client 5s
|
||||
timeout connect 5s
|
||||
timeout server 5s
|
||||
|
||||
frontend all 0.0.0.0:3000
|
||||
mode http
|
||||
timeout client 120s
|
||||
|
||||
option forwardfor
|
||||
option http-server-close
|
||||
option http-pretend-keepalive
|
||||
|
||||
default_backend sockets
|
||||
|
||||
backend sockets
|
||||
balance uri depth 2
|
||||
timeout server 120s
|
||||
server socket1 127.0.0.1:7000
|
||||
|
||||
@@ -55,10 +55,9 @@ var WebSocket = function(request, socket, head) {
|
||||
this._stream.addListener('data', function(data) {
|
||||
self._parser.parse(data);
|
||||
});
|
||||
this._stream.addListener('close', function() {
|
||||
self.close(1006, '', false);
|
||||
['close', 'end', 'error'].forEach(function(event) {
|
||||
self._stream.addListener(event, function() { self.close(1006, '', false) });
|
||||
});
|
||||
this._stream.addListener('error', function() {});
|
||||
};
|
||||
|
||||
var API = require('./websocket/api');
|
||||
|
||||
@@ -16,15 +16,12 @@ 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');
|
||||
} catch (e) {
|
||||
// socket closed while writing
|
||||
// no handshake sent; client will stop using WebSocket
|
||||
}
|
||||
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) {}
|
||||
},
|
||||
|
||||
parse: function(data) {
|
||||
|
||||
@@ -27,6 +27,25 @@ Draft76Parser.prototype.getVersion = function() {
|
||||
};
|
||||
|
||||
Draft76Parser.prototype.handshakeResponse = function(head) {
|
||||
var request = this._socket.request,
|
||||
stream = this._stream;
|
||||
|
||||
try {
|
||||
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');
|
||||
} catch (e) {}
|
||||
|
||||
this.handshakeSignature(head);
|
||||
};
|
||||
|
||||
Draft76Parser.prototype.handshakeSignature = function(head) {
|
||||
if (head.length === 0) return;
|
||||
this._handshakeComplete = true;
|
||||
|
||||
var request = this._socket.request,
|
||||
stream = this._stream,
|
||||
|
||||
@@ -43,16 +62,15 @@ 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(MD5.digest('binary'), 'binary');
|
||||
} catch (e) {
|
||||
// socket closed while writing
|
||||
// no handshake sent; client will stop using WebSocket
|
||||
}
|
||||
} catch (e) {};
|
||||
};
|
||||
|
||||
Draft76Parser.prototype.parse = function(data) {
|
||||
if (this._handshakeComplete)
|
||||
return Draft75Parser.prototype.parse.call(this, data);
|
||||
|
||||
this.handshakeSignature(data);
|
||||
};
|
||||
|
||||
module.exports = Draft76Parser;
|
||||
|
||||
@@ -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,14 +135,11 @@ 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');
|
||||
} catch (e) {
|
||||
// socket closed while writing
|
||||
// no handshake sent; client will stop using WebSocket
|
||||
}
|
||||
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) {}
|
||||
},
|
||||
|
||||
createHandshake: function() {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
, "author" : "James Coglan <jcoglan@gmail.com> (http://jcoglan.com/)"
|
||||
, "keywords" : ["websocket"]
|
||||
|
||||
, "version" : "0.1.1"
|
||||
, "version" : "0.1.2"
|
||||
, "engines" : {"node": ">=0.4.0"}
|
||||
, "main" : "./lib/faye/websocket"
|
||||
, "devDependencies" : {"jsclass": ">=3.0.4"}
|
||||
|
||||
Reference in New Issue
Block a user