12 Commits

13 changed files with 89 additions and 78 deletions
-7
View File
@@ -1,7 +0,0 @@
.git
.gitignore
.npmignore
.travis.yml
examples
node_modules
spec
+6 -3
View File
@@ -5,8 +5,11 @@ node_js:
- "0.8"
- "0.10"
- "0.12"
- "iojs-1"
- "iojs-2"
- "iojs-3"
- "4"
- "5"
- "6"
- "7"
- "8"
before_install:
- '[ "${TRAVIS_NODE_VERSION}" = "0.8" ] && npm install -g npm@~1.4.0 || true'
+5
View File
@@ -1,3 +1,8 @@
### 0.1.6 / 2017-09-10
* Use `9` instead of `8` as the `windowBits` parameter to zlib, to deal with
restrictions introduced in zlib v1.2.9
### 0.1.5 / 2016-02-24
* Catch errors thrown by `close()` on zlib streams
+20
View File
@@ -0,0 +1,20 @@
# The MIT License
Copyright (c) 2014-2017 James Coglan
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the 'Software'), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+1 -24
View File
@@ -11,7 +11,7 @@ WebSocket protocol extension as a plugin for
$ npm install permessage-deflate
```
## Usage
## Usage
Add the plugin to your extensions:
@@ -67,26 +67,3 @@ can be used to set the local session's behaviour and control that of the peer:
requested by the peer
* `requestMaxWindowBits`: an integer from `8` to `15` inclusive to ask the other
peer to use to set its maximum sliding window size, if supported
## License
(The MIT License)
Copyright (c) 2014-2016 James Coglan
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the 'Software'), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+1 -1
View File
@@ -39,7 +39,7 @@ ClientSession.prototype.generateOffer = function() {
if (this._requestMaxWindowBits !== undefined) {
if (common.VALID_WINDOW_BITS.indexOf(this._requestMaxWindowBits) < 0) {
throw new Error('Invalid valud for requestMaxWindowBits');
throw new Error('Invalid value for requestMaxWindowBits');
}
offer.server_max_window_bits = this._requestMaxWindowBits;
}
+1
View File
@@ -8,6 +8,7 @@ var common = {
'client_max_window_bits'
],
MIN_WINDOW_BITS: 9,
MAX_WINDOW_BITS: 15,
VALID_WINDOW_BITS: [8, 9, 10, 11, 12, 13, 14, 15],
+2 -1
View File
@@ -11,7 +11,8 @@ var VALID_OPTIONS = [
'noContextTakeover',
'maxWindowBits',
'requestNoContextTakeover',
'requestMaxWindowBits'
'requestMaxWindowBits',
'zlib'
];
var PermessageDeflate = {
+4 -4
View File
@@ -23,21 +23,21 @@ ServerSession.validParams = function(params) {
ServerSession.prototype.generateResponse = function() {
var response = {};
// https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression#section-8.1.1.1
// https://tools.ietf.org/html/rfc7692#section-7.1.1.1
this._ownContextTakeover = !this._acceptNoContextTakeover &&
!this._params.server_no_context_takeover;
if (!this._ownContextTakeover) response.server_no_context_takeover = true;
// https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression#section-8.1.1.2
// https://tools.ietf.org/html/rfc7692#section-7.1.1.2
this._peerContextTakeover = !this._requestNoContextTakeover &&
!this._params.client_no_context_takeover;
if (!this._peerContextTakeover) response.client_no_context_takeover = true;
// https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression#section-8.1.2.1
// https://tools.ietf.org/html/rfc7692#section-7.1.2.1
this._ownWindowBits = Math.min(this._acceptMaxWindowBits || common.MAX_WINDOW_BITS,
this._params.server_max_window_bits || common.MAX_WINDOW_BITS);
@@ -47,7 +47,7 @@ ServerSession.prototype.generateResponse = function() {
if (this._ownWindowBits < common.MAX_WINDOW_BITS && this._params.server_max_window_bits)
response.server_max_window_bits = this._ownWindowBits;
// https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression#section-8.1.2.2
// https://tools.ietf.org/html/rfc7692#section-7.1.2.2
var clientMax = this._params.client_max_window_bits, requestMax;
if (clientMax) {
+11 -4
View File
@@ -4,7 +4,7 @@ var zlib = require('zlib'),
common = require('./common');
var Session = function(options) {
this._level = common.fetch(options, 'level', zlib.Z_DEFAULT_LEVEL);
this._level = common.fetch(options, 'level', zlib.Z_DEFAULT_COMPRESSION);
this._memLevel = common.fetch(options, 'memLevel', zlib.Z_DEFAULT_MEMLEVEL);
this._strategy = common.fetch(options, 'strategy', zlib.Z_DEFAULT_STRATEGY);
@@ -15,6 +15,8 @@ var Session = function(options) {
this._queueIn = [];
this._queueOut = [];
this._zlib = common.fetch(options, 'zlib', zlib);
};
Session.prototype.processIncomingMessage = function(message, callback) {
@@ -123,7 +125,10 @@ Session.prototype.close = function() {
Session.prototype._getInflate = function() {
if (this._inflate) return this._inflate;
var inflate = zlib.createInflateRaw({windowBits: this._peerWindowBits});
var windowBits = Math.max(this._peerWindowBits, common.MIN_WINDOW_BITS),
inflate = this._zlib.createInflateRaw({windowBits: windowBits});
if (this._peerContextTakeover) this._inflate = inflate;
return inflate;
};
@@ -131,8 +136,10 @@ Session.prototype._getInflate = function() {
Session.prototype._getDeflate = function() {
if (this._deflate) return this._deflate;
var deflate = zlib.createDeflateRaw({
windowBits: this._ownWindowBits,
var windowBits = Math.max(this._ownWindowBits, common.MIN_WINDOW_BITS);
var deflate = this._zlib.createDeflateRaw({
windowBits: windowBits,
level: this._level,
memLevel: this._memLevel,
strategy: this._strategy
+6 -4
View File
@@ -5,12 +5,14 @@
, "keywords" : ["websocket", "compression", "deflate"]
, "license" : "MIT"
, "version" : "0.1.5"
, "engines" : {"node": ">=0.8.0"}
, "version" : "0.1.6"
, "engines" : { "node": ">=0.8.0" }
, "files" : ["lib"]
, "main" : "./lib/permessage_deflate"
, "devDependencies" : {"jstest": ""}
, "scripts" : {"test": "jstest spec/runner.js"}
, "devDependencies" : { "jstest": "*" }
, "scripts" : { "test": "jstest spec/runner.js" }
, "repository" : { "type" : "git"
, "url" : "git://github.com/faye/permessage-deflate-node.git"
+19 -18
View File
@@ -1,17 +1,18 @@
var PermessageDeflate = require('../lib/permessage_deflate'),
zlib = require('zlib'),
_zlib = require('zlib'),
test = require('jstest').Test
test.describe("ClientSession", function() { with(this) {
before(function() { with(this) {
this.ext = PermessageDeflate.configure(options)
this.session = ext.createClientSession()
this.deflate = zlibMock()
this.inflate = zlibMock()
this.level = zlib.Z_DEFAULT_LEVEL
this.memLevel = zlib.Z_DEFAULT_MEMLEVEL
this.strategy = zlib.Z_DEFAULT_STRATEGY
this.level = _zlib.Z_DEFAULT_LEVEL
this.memLevel = _zlib.Z_DEFAULT_MEMLEVEL
this.strategy = _zlib.Z_DEFAULT_STRATEGY
this.ext = PermessageDeflate.configure(options)
this.zlib = {}
this.session = ext.configure({zlib: zlib}).createClientSession()
this.message = {data: "hello", rsv1: true}
}})
@@ -127,9 +128,9 @@ test.describe("ClientSession", function() { with(this) {
assertEqual( true, activate() )
}})
it("uses context takeover and 8 window bits for inflating incoming messages", function() { with(this) {
it("uses context takeover and 9 window bits for inflating incoming messages", function() { with(this) {
activate()
expect(zlib, "createInflateRaw").given({windowBits: 8}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({windowBits: 9}).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
@@ -150,9 +151,9 @@ test.describe("ClientSession", function() { with(this) {
assertEqual( true, activate() )
}})
it("uses context takeover and 8 window bits for deflating outgoing messages", function() { with(this) {
it("uses context takeover and 9 window bits for deflating outgoing messages", function() { with(this) {
activate()
expect(zlib, "createDeflateRaw").given({windowBits: 8, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
expect(zlib, "createDeflateRaw").given({windowBits: 9, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
processOutgoingMessage()
processOutgoingMessage()
}})
@@ -224,9 +225,9 @@ test.describe("ClientSession", function() { with(this) {
assertEqual( true, activate() )
}})
it("uses context takeover and 8 window bits for deflating outgoing messages", function() { with(this) {
it("uses context takeover and 9 window bits for deflating outgoing messages", function() { with(this) {
activate()
expect(zlib, "createDeflateRaw").given({windowBits: 8, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
expect(zlib, "createDeflateRaw").given({windowBits: 9, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
processOutgoingMessage()
processOutgoingMessage()
}})
@@ -317,11 +318,11 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with level", function() { with(this) {
define("options", {level: zlib.Z_BEST_SPEED})
define("options", {level: _zlib.Z_BEST_SPEED})
it("sets the level of the deflate stream", function() { with(this) {
activate()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: zlib.Z_BEST_SPEED, memLevel: memLevel, strategy: strategy}).returns(deflate)
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: _zlib.Z_BEST_SPEED, memLevel: memLevel, strategy: strategy}).returns(deflate)
processOutgoingMessage()
}})
}})
@@ -331,17 +332,17 @@ test.describe("ClientSession", function() { with(this) {
it("sets the memLevel of the deflate stream", function() { with(this) {
activate()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: zlib.Z_DEFAULT_LEVEL, memLevel: 5, strategy: strategy}).returns(deflate)
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: _zlib.Z_DEFAULT_LEVEL, memLevel: 5, strategy: strategy}).returns(deflate)
processOutgoingMessage()
}})
}})
describe("with strategy", function() { with(this) {
define("options", {strategy: zlib.Z_FILTERED})
define("options", {strategy: _zlib.Z_FILTERED})
it("sets the strategy of the deflate stream", function() { with(this) {
activate()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: zlib.Z_DEFAULT_LEVEL, memLevel: memLevel, strategy: zlib.Z_FILTERED}).returns(deflate)
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: _zlib.Z_DEFAULT_LEVEL, memLevel: memLevel, strategy: _zlib.Z_FILTERED}).returns(deflate)
processOutgoingMessage()
}})
}})
+13 -12
View File
@@ -1,17 +1,18 @@
var PermessageDeflate = require('../lib/permessage_deflate'),
zlib = require('zlib'),
_zlib = require('zlib'),
test = require('jstest').Test
test.describe("ServerSession", function() { with(this) {
before(function() { with(this) {
this.ext = PermessageDeflate.configure(options)
this.session = ext.createServerSession([offer])
this.deflate = zlibMock()
this.inflate = zlibMock()
this.level = zlib.Z_DEFAULT_LEVEL
this.memLevel = zlib.Z_DEFAULT_MEMLEVEL
this.strategy = zlib.Z_DEFAULT_STRATEGY
this.level = _zlib.Z_DEFAULT_LEVEL
this.memLevel = _zlib.Z_DEFAULT_MEMLEVEL
this.strategy = _zlib.Z_DEFAULT_STRATEGY
this.ext = PermessageDeflate.configure(options)
this.zlib = {}
this.session = ext.configure({zlib: zlib}).createServerSession([offer])
this.message = {data: "hello", rsv1: true}
}})
@@ -319,11 +320,11 @@ test.describe("ServerSession", function() { with(this) {
}})
describe("with level", function() { with(this) {
define("options", {level: zlib.Z_BEST_SPEED})
define("options", {level: _zlib.Z_BEST_SPEED})
it("sets the level of the deflate stream", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: zlib.Z_BEST_SPEED, memLevel: memLevel, strategy: strategy}).returns(deflate)
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: _zlib.Z_BEST_SPEED, memLevel: memLevel, strategy: strategy}).returns(deflate)
processOutgoingMessage()
}})
}})
@@ -333,17 +334,17 @@ test.describe("ServerSession", function() { with(this) {
it("sets the memLevel of the deflate stream", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: zlib.Z_DEFAULT_LEVEL, memLevel: 5, strategy: strategy}).returns(deflate)
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: _zlib.Z_DEFAULT_LEVEL, memLevel: 5, strategy: strategy}).returns(deflate)
processOutgoingMessage()
}})
}})
describe("with strategy", function() { with(this) {
define("options", {strategy: zlib.Z_FILTERED})
define("options", {strategy: _zlib.Z_FILTERED})
it("sets the strategy of the deflate stream", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: zlib.Z_DEFAULT_LEVEL, memLevel: memLevel, strategy: zlib.Z_FILTERED}).returns(deflate)
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: _zlib.Z_DEFAULT_LEVEL, memLevel: memLevel, strategy: _zlib.Z_FILTERED}).returns(deflate)
processOutgoingMessage()
}})
}})