Compare commits

..

11 Commits

Author SHA1 Message Date
James Coglan 73284c858c Bump version to 0.9.1. 2014-12-18 02:25:03 +00:00
James Coglan ec5838e27e Typo; I'd used . instead of , in an arglist. 2014-12-17 22:50:19 +00:00
James Coglan 2627293613 Validate the option names passed into the WebSocket constructor. 2014-12-17 22:42:34 +00:00
James Coglan 4f1eced5e0 Bump version to 0.9.0 and document how to add extensions. 2014-12-13 14:03:37 +00:00
James Coglan ca0544fa6a Revert 29d07c5; see https://github.com/faye/faye-websocket-node/pull/34 2014-12-13 01:25:33 +00:00
James Coglan 091d98ef0c Merge pull request #34 from lpinca/fix/close-on-handshake
Handle cases where the socket is closed before being passed to the server
2014-12-13 00:15:22 +00:00
James Coglan 8d1f652056 Stylistic tweaks to the Autobahn client. 2014-12-06 10:51:18 +00:00
Luigi Pinca b779876f07 Handle cases where the socket is closed before being passed to the server
See #32
2014-11-26 16:08:05 +01:00
James Coglan 243e39b7b7 Refactor the Autobahn client script. 2014-11-24 22:05:56 +00:00
James Coglan 04eda7bc4f Allow the user to pass extensions through to websocket-driver via the WebSocket constructor. 2014-11-24 00:37:12 +00:00
James Coglan 43ac090594 Add vanilla request support to the proxy server. 2014-11-23 21:56:51 +00:00
8 changed files with 109 additions and 37 deletions
+10
View File
@@ -1,3 +1,13 @@
### 0.9.1 / 2014-12-18
* Check that all options to the WebSocket constructor are recognized
### 0.9.0 / 2014-12-13
* Allow protocol extensions to be passed into websocket-extensions
### 0.8.1 / 2014-11-12
* Send the correct hostname when upgrading a connection to TLS
+19
View File
@@ -157,6 +157,22 @@ If the client and server agree on a protocol, both the client- and server-side
socket objects expose the selected protocol through the `ws.protocol` property.
## Protocol extensions
faye-websocket is based on the
[websocket-extensions](https://github.com/faye/websocket-extensions-node)
framework that allows extensions to be negotiated via the
`Sec-WebSocket-Extensions` header. To add extensions to a connection, pass an
array of extensions to the `:extensions` option. For example, to add
[permessage-deflate](https://github.com/faye/permessage-deflate-node):
```js
var deflate = require('permessage-deflate');
var ws = new WebSocket(request, null, {extensions: [deflate]});
```
## Initialization options
Both the server- and client-side classes allow an options object to be passed
@@ -170,6 +186,9 @@ var ws = new WebSocket.Client(url, protocols, options);
`protocols` is an array of subprotocols as described above, or `null`.
`options` is an optional object containing any of these fields:
* `extensions` - an array of
[websocket-extensions](https://github.com/faye/websocket-extensions-node)
compatible extensions, as described above
* `headers` - an object containing key-value pairs representing HTTP headers to
be sent during the handshake process
* `maxLength` - the maximum allowed size of incoming message frames, in bytes.
+23 -22
View File
@@ -1,13 +1,14 @@
var WebSocket = require('../lib/faye/websocket'),
deflate = require('permessage-deflate'),
pace = require('pace');
var host = 'ws://localhost:9001',
agent = 'node-' + process.version,
cases = 0,
skip = [];
var host = 'ws://localhost:9001',
agent = encodeURIComponent('node-' + process.version),
cases = 0,
options = {extensions: [deflate]};
var socket = new WebSocket.Client(host + '/getCaseCount'),
progress;
url, progress;
socket.onmessage = function(event) {
console.log('Total cases to run: ' + event.data);
@@ -15,24 +16,24 @@ socket.onmessage = function(event) {
progress = pace(cases);
};
socket.onclose = function() {
var runCase = function(n) {
if (n > cases) {
socket = new WebSocket.Client(host + '/updateReports?agent=' + encodeURIComponent(agent));
socket.onclose = process.exit;
return;
}
var runCase = function(n) {
if (n > cases) {
url = host + '/updateReports?agent=' + agent;
socket = new WebSocket.Client(url);
socket.onclose = process.exit;
return;
}
url = host + '/runCase?case=' + n + '&agent=' + agent;
socket = new WebSocket.Client(url, null, options);
socket.pipe(socket);
socket.on('close', function() {
progress.op();
runCase(n + 1);
});
};
if (skip.indexOf(n) >= 0) {
runCase(n + 1);
} else {
socket = new WebSocket.Client(host + '/runCase?case=' + n + '&agent=' + encodeURIComponent(agent));
socket.pipe(socket);
socket.on('close', function() { runCase(n + 1) });
}
};
socket.onclose = function() {
runCase(1);
};
+5 -3
View File
@@ -1,13 +1,15 @@
var WebSocket = require('../lib/faye/websocket'),
deflate = require('permessage-deflate'),
fs = require('fs'),
http = require('http'),
https = require('https');
var port = process.argv[2] || 7000,
secure = process.argv[3] === 'tls';
var port = process.argv[2] || 7000,
secure = process.argv[3] === 'tls',
options = {extensions: [deflate], ping: 5};
var upgradeHandler = function(request, socket, head) {
var ws = new WebSocket(request, socket, head, ['irc', 'xmpp'], {ping: 5});
var ws = new WebSocket(request, socket, head, ['irc', 'xmpp'], options);
console.log('[open]', ws.url, ws.version, ws.protocol, request.headers);
ws.pipe(ws);
+6 -1
View File
@@ -1,5 +1,5 @@
// API references:
//
//
// * http://dev.w3.org/html5/websockets/
// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget
// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-event
@@ -16,6 +16,7 @@ var WebSocket = function(request, socket, body, protocols, options) {
var self = this;
if (!this._stream || !this._stream.writable) return;
if (!this._stream.readable) return this._stream.end();
var catchup = function() { self._stream.removeListener('data', catchup) };
this._stream.on('data', catchup);
@@ -33,6 +34,10 @@ WebSocket.isWebSocket = function(request) {
return driver.isWebSocket(request);
};
WebSocket.validateOptions = function(options, validKeys) {
driver.validateOptions(options, validKeys);
};
WebSocket.WebSocket = WebSocket;
WebSocket.Client = require('./websocket/client');
WebSocket.EventSource = require('./eventsource');
+8 -7
View File
@@ -1,10 +1,12 @@
var Stream = require('stream').Stream,
util = require('util'),
driver = require('websocket-driver'),
EventTarget = require('./api/event_target'),
Event = require('./api/event');
var API = function(options) {
options = options || {};
driver.validateOptions(options, ['headers', 'extensions', 'maxLength', 'ping', 'proxy', 'tls', 'ca']);
this.readable = this.writable = true;
@@ -13,6 +15,11 @@ var API = function(options) {
for (var name in headers) this._driver.setHeader(name, headers[name]);
}
var extensions = options.extensions;
if (extensions) {
[].concat(extensions).forEach(this._driver.addExtension, this._driver);
}
this._ping = options.ping;
this._pingId = 0;
this.readyState = API.CONNECTING;
@@ -134,13 +141,7 @@ var instance = {
this.readyState = API.CLOSED;
if (this._pingTimer) clearInterval(this._pingTimer);
var stream = this._stream;
if (stream) {
if (stream.unpipe) stream.unpipe(this._driver.io);
stream.on('data', function() { stream.destroy() });
stream.end();
}
if (this._stream) this._stream.end();
if (this.readable) this.emit('end');
this.readable = this.writable = false;
+3 -3
View File
@@ -5,11 +5,11 @@
, "keywords" : ["websocket", "eventsource"]
, "license" : "MIT"
, "version" : "0.8.1"
, "version" : "0.9.1"
, "engines" : {"node": ">=0.4.0"}
, "main" : "./lib/faye/websocket"
, "dependencies" : {"websocket-driver": ">=0.4.0"}
, "devDependencies" : {"jstest": "", "pace": ""}
, "dependencies" : {"websocket-driver": ">=0.5.1"}
, "devDependencies" : {"jstest": "", "pace": "", "permessage-deflate": ""}
, "scripts" : {"test": "jstest spec/runner.js"}
+35 -1
View File
@@ -1,7 +1,11 @@
var fs = require('fs'),
http = require('http'),
https = require('https'),
net = require('net');
net = require('net'),
url = require('url');
var AGENTS = {'http:': http, 'https:': https},
PORTS = {'http:': 80, 'https:': 443};
var ProxyServer = function(options) {
var proxy = options.tls
@@ -13,6 +17,35 @@ var ProxyServer = function(options) {
options = options || {};
var onRequest = function(request, response) {
if (options.debug) console.log(request.method, request.url, request.headers);
var uri = url.parse(request.url),
agent = AGENTS[uri.protocol],
headers = {};
for (var key in request.headers) {
if (key.split('-')[0] !== 'proxy') headers[key] = request.headers[key];
}
var backend = agent.request({
method: request.method,
host: uri.hostname,
port: uri.port || PORTS[uri.protocol],
path: uri.path,
headers: headers,
rejectUnauthorized: false
});
request.pipe(backend);
backend.on('response', function(resp) {
if (options.debug) console.log(resp.statusCode, resp.headers);
response.writeHead(resp.statusCode, resp.headers);
resp.pipe(response);
});
};
var onConnect = function(request, frontend, body) {
var parts = request.url.split(':'),
backend = net.connect(parts[1], parts[0]);
@@ -31,6 +64,7 @@ var ProxyServer = function(options) {
backend.on( 'data', function(data) { console.log('O', data) });
};
proxy.on('request', onRequest);
proxy.on('connect', onConnect);
proxy.on('upgrade', onConnect);