From 3a0ca03671bffc7861f128e02ee7d9a8f651d6ae Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sun, 21 May 2017 11:15:40 +0200 Subject: [PATCH 1/3] Update ws to version 3.x --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 56dceb7..07f0d4e 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "inherits": "^2.0.1", "readable-stream": "^2.2.0", "safe-buffer": "^5.0.1", - "ws": "^2.2.3", + "ws": "^3.0.0", "xtend": "^4.0.0" }, "devDependencies": { From 297a5588bfc56d058e8a0bf6667d2679064f2a1a Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sun, 21 May 2017 12:38:39 +0200 Subject: [PATCH 2/3] Update documentation for options.perMessageDeflate --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 07964b3..2a9a4e7 100644 --- a/readme.md +++ b/readme.md @@ -54,7 +54,7 @@ We recommend disabling the [per message deflate extension](https://tools.ietf.org/html/rfc7692) to achieve the best throughput. -Default: `true` +Default: `true` on the client, `false` on the server. Example: @@ -65,7 +65,7 @@ var ws = websocket('ws://realtimecats.com', { }) ``` -Beware that this is the only one option you cannot set on the client. You must set it on the server and this will be negotiated with the client. +Beware that this option is ignored by browser clients. To make sure that permessage-deflate is never used, disable it on the server. ##### Other options From 6383c7949d1b7255dbdeaa2eb364c9271eb443d4 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sun, 21 May 2017 13:17:02 +0200 Subject: [PATCH 3/3] Forward the request argument to the stream event --- readme.md | 3 ++- server.js | 4 ++-- test.js | 11 +++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index 2a9a4e7..32014a7 100644 --- a/readme.md +++ b/readme.md @@ -79,7 +79,8 @@ Using the [`ws`](http://npmjs.org/ws) module you can make a websocket server and var websocket = require('websocket-stream') var wss = websocket.createServer({server: someHTTPServer}, handle) -function handle(stream) { +function handle(stream, request) { + // `request` is the upgrade request sent by the client. fs.createReadStream('bigdata.json').pipe(stream) } ``` diff --git a/server.js b/server.js index 55cd155..c6154e6 100644 --- a/server.js +++ b/server.js @@ -11,8 +11,8 @@ class Server extends WebSocketServer{ this.on('newListener', function(event) { if (!proxied && event === 'stream') { proxied = true - this.on('connection', function(conn) { - this.emit('stream', stream(conn, opts)) + this.on('connection', function(conn, req) { + this.emit('stream', stream(conn, opts), req) }) } }) diff --git a/test.js b/test.js index 8fd9170..d4a891b 100644 --- a/test.js +++ b/test.js @@ -193,10 +193,10 @@ test('error on socket should forward it to pipe', function(t) { test('stream end', function(t) { t.plan(1) - + var server = http.createServer() websocket.createServer({ server: server }, handle) - + function handle (stream) { stream.pipe(concat(function (body) { t.equal(body.toString(), 'pizza cats\n') @@ -210,7 +210,7 @@ test('stream end', function(t) { }) test('stream handlers should fire once per connection', function(t) { - t.plan(1) + t.plan(2) var server = http.createServer() var wss = websocket.createServer({ server: server }, function() { @@ -220,7 +220,10 @@ test('stream handlers should fire once per connection', function(t) { }) var m = 0 - wss.on('stream', function() { m++ }) + wss.on('stream', function(stream, request) { + t.ok(request instanceof http.IncomingMessage) + m++ + }) server.listen(0, function() { var w = websocket('ws://localhost:' + server.address().port) w.end('pizza cats\n')