33 Commits

Author SHA1 Message Date
James Coglan 68ceed8cf8 Test on recent versions of Node 2023-09-07 19:24:32 +01:00
James Coglan 947ad6692b Switch from Travis CI to GitHub Actions 2021-05-18 22:11:31 +01:00
James Coglan 8ee77a23c0 Travis update: cache npm modules, remove sudo, run on Node 15 2021-03-12 21:37:13 +00:00
James Coglan 5eddd922aa Add Node versions 13 and 14 on Travis 2020-05-14 23:52:45 +01:00
James Coglan 75b434c6a0 Mention license change in the changelog 2019-06-13 11:38:41 +01:00
James Coglan ae94112fe9 Formatting change: {...} should have spaces inside the braces 2019-06-11 15:50:38 +01:00
James Coglan 5a74a0471b Bump version to 0.1.7 2019-06-10 12:14:40 +01:00
James Coglan 3500cddfa7 Let npm reformat package.json 2019-06-10 12:12:33 +01:00
James Coglan 8d58a3363d Use the newer safe Buffer API instead of the constructor 2019-06-07 18:41:35 +01:00
James Coglan f104377a0e Change markdown formatting of docs. 2019-05-29 15:37:32 +01:00
James Coglan 8ddfd06f5b Update Travis target versions. 2019-05-24 14:03:38 +01:00
James Coglan 33df77ef24 Switch license to Apache 2.0. 2019-05-24 13:56:04 +01:00
James Coglan 0594d1b16b Bump version to 0.1.6. 2017-09-10 17:40:58 +01:00
James Coglan 3fc65a8277 Move the license into its own file. 2017-09-10 17:39:05 +01:00
James Coglan c0ef506072 Use package.json instead of .npmignore to set files in the package. 2017-09-10 17:38:46 +01:00
James Coglan 689e37cfb7 Use windowBits:9 for deflate and inflate streams if the session is configured to use 8. 2017-09-08 22:29:37 +01:00
James Coglan 7abe8c8a7f Update spec URLs from the draft spec to RFC 7692. 2017-08-18 09:46:01 +01:00
James Coglan cbae000ab3 Use Z_DEFAULT_COMPRESSION rather than Z_DEFAULT_LEVEL, it's more descriptive. 2017-08-18 09:32:57 +01:00
James Coglan 9e8a72316d Correct a typo in an error message. 2017-08-17 22:15:58 +01:00
James Coglan 2f277e23c8 Drop testing for io.js releases, which barely anybody is still using. 2017-08-01 23:47:55 +01:00
James Coglan 0215b35a21 In Node 8, the zlib API is read-only and so cannot be stubbed on the real module. Therefore we need to pass in an object to replace the zlib module in the code under test, on which we can mock/stub method calls. 2017-08-01 01:13:54 +01:00
James Coglan f98b56db0f Test on Node 7 and 8. 2017-08-01 00:54:02 +01:00
James Coglan cad0e4f121 Remove non-breaking spaces from README. 2016-10-08 03:10:52 +01:00
James Coglan 0e8539acf7 Test on Node 6.0. 2016-04-30 13:08:52 +01:00
James Coglan 48a078f8e7 Bump version to 0.1.5 and drop support for Node 0.6. 2016-02-24 08:29:42 +00:00
James Coglan 60764f5757 Bump the copyright year. 2016-02-06 19:15:25 +00:00
James Coglan 6b75657a94 Use https: URLs for github.com in package.json. 2016-02-06 19:15:03 +00:00
James Coglan d22edec996 Catch errors thrown by close() on zlib streams. If they throw, we were about to discard them anyway, so there's no need to do anything. 2016-02-06 14:22:53 +00:00
James Coglan 1d219334bf Create CODE_OF_CONDUCT.md. 2015-11-08 12:16:23 +00:00
James Coglan 913b174ea1 Bump version to 0.1.4. 2015-11-06 22:08:35 +00:00
James Coglan 0eb99773db Test on Node 5. 2015-11-05 21:22:05 +00:00
James Coglan 758ed46420 Run tests on major versions of iojs and node 4. 2015-10-17 12:56:52 +01:00
James Coglan 9cb62ecd49 Refactor ServerSession.generateResponse() to group all logic around setting each parameter -- both the internal setting and the response value -- together, and from here work around an issue in Firefox that means the client will fail if the server sends an unsolicited server_max_window_bits parameter. 2015-10-11 13:21:04 +01:00
17 changed files with 331 additions and 244 deletions
+41
View File
@@ -0,0 +1,41 @@
on:
- push
- pull_request
jobs:
test:
strategy:
fail-fast: false
matrix:
node:
- '0.8'
- '0.10'
- '0.12'
- '4'
- '6'
- '8'
- '10'
- '12'
- '14'
- '16'
- '18'
- '20'
name: node.js v${{ matrix.node }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- if: matrix.node == '0.8'
run: npm conf set strict-ssl false
- run: node --version
- run: npm install
- run: npm install 'nopt@5'
- run: rm -rf node_modules/jstest/node_modules/nopt
- run: npm test
+1
View File
@@ -1 +1,2 @@
node_modules
package-lock.json
-7
View File
@@ -1,7 +0,0 @@
.git
.gitignore
.npmignore
.travis.yml
examples
node_modules
spec
-11
View File
@@ -1,11 +0,0 @@
language: node_js
node_js:
- "0.6"
- "0.8"
- "0.10"
- "0.12"
- "iojs"
before_install:
- '[ "${TRAVIS_NODE_VERSION}" = "0.6" ] && npm conf set strict-ssl false || true'
+26 -6
View File
@@ -1,19 +1,39 @@
### 0.1.7 / 2019-06-10
- Use the `Buffer.alloc()` and `Buffer.from()` functions instead of the unsafe
`Buffer()` constructor
- Change license from MIT to Apache 2.0
### 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
### 0.1.4 / 2015-11-06
- The server does not send `server_max_window_bits` if the client does not ask
for it; this works around an issue in Firefox.
### 0.1.3 / 2015-04-10
* Fix a race condition causing some fragments of deflate output to be dropped
* Make sure to emit minimal output on all Node versions
- Fix a race condition causing some fragments of deflate output to be dropped
- Make sure to emit minimal output on all Node versions
### 0.1.2 / 2014-12-18
* Don't allow configure() to be called with unrecognized options
- Don't allow configure() to be called with unrecognized options
### 0.1.1 / 2014-12-15
* Fix race condition when using context takeover, where adjacent messages have
- Fix race condition when using context takeover, where adjacent messages have
data listeners bound at the same time and end up duplicating output
* Use `DeflateRaw.flush()` correctly on v0.10 so that optimal compression is
- Use `DeflateRaw.flush()` correctly on v0.10 so that optimal compression is
achieved
### 0.1.0 / 2014-12-13
* Initial release
- Initial release
+4
View File
@@ -0,0 +1,4 @@
# Code of Conduct
All projects under the [Faye](https://github.com/faye) umbrella are covered by
the [Code of Conduct](https://github.com/faye/code-of-conduct).
+12
View File
@@ -0,0 +1,12 @@
Copyright 2014-2019 James Coglan
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
+9 -32
View File
@@ -1,4 +1,4 @@
# permessage-deflate [![Build status](https://secure.travis-ci.org/faye/permessage-deflate-node.svg)](http://travis-ci.org/faye/permessage-deflate-node)
# permessage-deflate
Implements the
[permessage-deflate](https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression)
@@ -11,7 +11,7 @@ WebSocket protocol extension as a plugin for
$ npm install permessage-deflate
```
## Usage
## Usage
Add the plugin to your extensions:
@@ -45,48 +45,25 @@ the peer, and those that are negotiated as part of the protocol. The settings
only affecting the compressor are described fully in the [zlib
documentation](http://nodejs.org/api/zlib.html#zlib_options):
* `level`: sets the compression level, can be an integer from `0` to `9`, or one
- `level`: sets the compression level, can be an integer from `0` to `9`, or one
of the constants `zlib.Z_NO_COMPRESSION`, `zlib.Z_BEST_SPEED`,
`zlib.Z_BEST_COMPRESSION`, or `zlib.Z_DEFAULT_COMPRESSION`
* `memLevel`: sets how much memory the compressor allocates, can be an integer
- `memLevel`: sets how much memory the compressor allocates, can be an integer
from `1` to `9`, or one of the constants `zlib.Z_MIN_MEMLEVEL`,
`zlib.Z_MAX_MEMLEVEL`, or `zlib.Z_DEFAULT_MEMLEVEL`
* `strategy`: can be one of the constants `zlib.Z_FILTERED`,
- `strategy`: can be one of the constants `zlib.Z_FILTERED`,
`zlib.Z_HUFFMAN_ONLY`, `zlib.Z_RLE`, `zlib.Z_FIXED`, or
`zlib.Z_DEFAULT_STRATEGY`
The other options relate to settings that are negotiated via the protocol and
can be used to set the local session's behaviour and control that of the peer:
* `noContextTakeover`: if `true`, stops the session reusing a deflate context
- `noContextTakeover`: if `true`, stops the session reusing a deflate context
between messages
* `requestNoContextTakeover`: if `true`, makes the session tell the other peer
- `requestNoContextTakeover`: if `true`, makes the session tell the other peer
not to reuse a deflate context between messages
* `maxWindowBits`: an integer from `8` to `15` inclusive that sets the maximum
- `maxWindowBits`: an integer from `8` to `15` inclusive that sets the maximum
size of the session's sliding window; a lower window size will be used if
requested by the peer
* `requestMaxWindowBits`: an integer from `8` to `15` inclusive to ask the other
- `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-2015 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
@@ -22,7 +22,7 @@ function compress(index) {
return decompress(0);
}
var message = {data: new Buffer(record[3], 'base64')};
var message = { data: new Buffer(record[3], 'base64') };
size[0] += message.data.length;
server.processOutgoingMessage(message, function(error, message) {
+4 -4
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;
}
@@ -64,12 +64,12 @@ ClientSession.prototype.activate = function(params) {
this._ownContextTakeover = !(this._acceptNoContextTakeover || params.client_no_context_takeover);
this._ownWindowBits = Math.min(
this._acceptMaxWindowBits || common.DEFAULT_MAX_WINDOW_BITS,
params.client_max_window_bits || common.DEFAULT_MAX_WINDOW_BITS
this._acceptMaxWindowBits || common.MAX_WINDOW_BITS,
params.client_max_window_bits || common.MAX_WINDOW_BITS
);
this._peerContextTakeover = !params.server_no_context_takeover;
this._peerWindowBits = params.server_max_window_bits || common.DEFAULT_MAX_WINDOW_BITS;
this._peerWindowBits = params.server_max_window_bits || common.MAX_WINDOW_BITS;
return true;
};
+4 -12
View File
@@ -1,5 +1,7 @@
'use strict';
var Buffer = require('safe-buffer').Buffer;
var common = {
VALID_PARAMS: [
'server_no_context_takeover',
@@ -8,20 +10,10 @@ var common = {
'client_max_window_bits'
],
DEFAULT_MAX_WINDOW_BITS: 15,
MIN_WINDOW_BITS: 9,
MAX_WINDOW_BITS: 15,
VALID_WINDOW_BITS: [8, 9, 10, 11, 12, 13, 14, 15],
concat: function(buffers, length) {
var buffer = new Buffer(length),
offset = 0;
for (var i = 0, n = buffers.length; i < n; i++) {
buffers[i].copy(buffer, offset);
offset += buffers[i].length;
}
return buffer;
},
fetch: function(options, key, _default) {
if (options.hasOwnProperty(key))
return options[key];
+3 -2
View File
@@ -11,7 +11,8 @@ var VALID_OPTIONS = [
'noContextTakeover',
'maxWindowBits',
'requestNoContextTakeover',
'requestMaxWindowBits'
'requestMaxWindowBits',
'zlib'
];
var PermessageDeflate = {
@@ -19,7 +20,7 @@ var PermessageDeflate = {
common.validateOptions(options, VALID_OPTIONS);
var opts = this._options || {};
for (var key in opts) options[key] = opts[key];
return Object.create(this, {_options: {value: options}});
return Object.create(this, { _options: { value: options }});
},
createClientSession: function() {
+31 -27
View File
@@ -21,42 +21,46 @@ ServerSession.validParams = function(params) {
};
ServerSession.prototype.generateResponse = function() {
var params = {};
var response = {};
// https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression#section-8.1.1.1
if (this._acceptNoContextTakeover || this._params.server_no_context_takeover)
params.server_no_context_takeover = true;
// https://tools.ietf.org/html/rfc7692#section-7.1.1.1
// https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression#section-8.1.1.2
if (this._requestNoContextTakeover || this._params.client_no_context_takeover)
params.client_no_context_takeover = true;
this._ownContextTakeover = !this._acceptNoContextTakeover &&
!this._params.server_no_context_takeover;
// https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression#section-8.1.2.1
var acceptMax, serverMax;
if (this._acceptMaxWindowBits || this._params.server_max_window_bits) {
acceptMax = this._acceptMaxWindowBits || common.DEFAULT_MAX_WINDOW_BITS;
serverMax = this._params.server_max_window_bits || common.DEFAULT_MAX_WINDOW_BITS;
params.server_max_window_bits = Math.min(acceptMax, serverMax);
}
if (!this._ownContextTakeover) response.server_no_context_takeover = true;
// 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/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);
// In violation of the spec, Firefox closes the connection if it does not
// send server_max_window_bits but the server includes this in its response
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/rfc7692#section-7.1.2.2
// https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression#section-8.1.2.2
var clientMax = this._params.client_max_window_bits, requestMax;
if (clientMax) {
if (clientMax === true) {
if (this._requestMaxWindowBits) params.client_max_window_bits = this._requestMaxWindowBits;
} else {
requestMax = this._requestMaxWindowBits || common.DEFAULT_MAX_WINDOW_BITS;
params.client_max_window_bits = Math.min(requestMax, clientMax);
}
if (clientMax === true) clientMax = common.MAX_WINDOW_BITS;
this._peerWindowBits = Math.min(this._requestMaxWindowBits || common.MAX_WINDOW_BITS, clientMax);
} else {
this._peerWindowBits = common.MAX_WINDOW_BITS;
}
this._ownContextTakeover = !params.server_no_context_takeover;
this._ownWindowBits = params.server_max_window_bits || common.DEFAULT_MAX_WINDOW_BITS;
if (this._peerWindowBits < common.MAX_WINDOW_BITS)
response.client_max_window_bits = this._peerWindowBits;
this._peerContextTakeover = !params.client_no_context_takeover;
this._peerWindowBits = params.client_max_window_bits || common.DEFAULT_MAX_WINDOW_BITS;
return params;
return response;
};
module.exports = ServerSession;
+26 -13
View File
@@ -1,10 +1,11 @@
'use strict';
var zlib = require('zlib'),
var Buffer = require('safe-buffer').Buffer,
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 +16,8 @@ var Session = function(options) {
this._queueIn = [];
this._queueOut = [];
this._zlib = common.fetch(options, 'zlib', zlib);
};
Session.prototype.processIncomingMessage = function(message, callback) {
@@ -33,7 +36,7 @@ Session.prototype.processIncomingMessage = function(message, callback) {
inflate.removeListener('data', onData);
inflate.removeListener('error', onError);
if (!self._inflate && inflate.close) inflate.close();
if (!self._inflate) self._close(inflate);
self._lockIn = false;
var next = self._queueIn.shift();
@@ -55,10 +58,10 @@ Session.prototype.processIncomingMessage = function(message, callback) {
inflate.on('error', onError);
inflate.write(message.data);
inflate.write(new Buffer([0x00, 0x00, 0xff, 0xff]));
inflate.write(Buffer.from([0x00, 0x00, 0xff, 0xff]));
inflate.flush(function() {
message.data = common.concat(chunks, length);
message.data = Buffer.concat(chunks, length);
return_(null, message);
});
};
@@ -78,7 +81,7 @@ Session.prototype.processOutgoingMessage = function(message, callback) {
deflate.removeListener('data', onData);
deflate.removeListener('error', onError);
if (!self._deflate && deflate.close) deflate.close();
if (!self._deflate) self._close(deflate);
self._lockOut = false;
var next = self._queueOut.shift();
@@ -101,7 +104,7 @@ Session.prototype.processOutgoingMessage = function(message, callback) {
deflate.write(message.data);
var onFlush = function() {
var data = common.concat(chunks, length);
var data = Buffer.concat(chunks, length);
message.data = data.slice(0, data.length - 4);
message.rsv1 = true;
return_(null, message);
@@ -114,16 +117,19 @@ Session.prototype.processOutgoingMessage = function(message, callback) {
};
Session.prototype.close = function() {
if (this._inflate && this._inflate.close) this._inflate.close();
this._close(this._inflate);
this._inflate = null;
if (this._deflate && this._deflate.close) this._deflate.close();
this._close(this._deflate);
this._deflate = null;
};
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 +137,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
@@ -151,7 +159,7 @@ Session.prototype._getDeflate = function() {
flush.call(this, callback);
} else {
this._flushFlag = zlib.Z_SYNC_FLUSH;
this.write(new Buffer(0), '', callback);
this.write(Buffer.alloc(0), '', callback);
}
};
@@ -159,4 +167,9 @@ Session.prototype._getDeflate = function() {
return deflate;
};
Session.prototype._close = function(codec) {
if (!codec || !codec.close) return;
try { codec.close() } catch (error) {}
};
module.exports = Session;
+33 -19
View File
@@ -1,20 +1,34 @@
{ "name" : "permessage-deflate"
, "description" : "Per-message DEFLATE compression extension for WebSocket connections"
, "homepage" : "http://github.com/faye/permessage-deflate-node"
, "author" : "James Coglan <jcoglan@gmail.com> (http://jcoglan.com/)"
, "keywords" : ["websocket", "compression", "deflate"]
, "license" : "MIT"
, "version" : "0.1.3"
, "engines" : {"node": ">=0.6.0"}
, "main" : "./lib/permessage_deflate"
, "devDependencies" : {"jstest": ""}
, "scripts" : {"test": "jstest spec/runner.js"}
, "repository" : { "type" : "git"
, "url" : "git://github.com/faye/permessage-deflate-node.git"
}
, "bugs" : "http://github.com/faye/permessage-deflate-node/issues"
{
"name": "permessage-deflate",
"description": "Per-message DEFLATE compression extension for WebSocket connections",
"homepage": "https://github.com/faye/permessage-deflate-node",
"author": "James Coglan <jcoglan@gmail.com> (http://jcoglan.com/)",
"keywords": [
"websocket",
"compression",
"deflate"
],
"license": "Apache-2.0",
"version": "0.1.7",
"engines": {
"node": ">=0.8.0"
},
"files": [
"lib"
],
"main": "./lib/permessage_deflate",
"dependencies": {
"safe-buffer": "*"
},
"devDependencies": {
"jstest": "*"
},
"scripts": {
"test": "jstest spec/runner.js"
},
"repository": {
"type": "git",
"url": "git://github.com/faye/permessage-deflate-node.git"
},
"bugs": "https://github.com/faye/permessage-deflate-node/issues"
}
+63 -50
View File
@@ -1,19 +1,20 @@
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.message = {data: "hello", rsv1: true}
this.ext = PermessageDeflate.configure(options)
this.zlib = {}
this.session = ext.configure({ zlib: zlib }).createClientSession()
this.message = { data: "hello", rsv1: true }
}})
define("zlibMock", function() {
@@ -53,7 +54,7 @@ test.describe("ClientSession", function() { with(this) {
describe("with default options", function() { with(this) {
it("indicates support for client_max_window_bits", function() { with(this) {
assertEqual( {client_max_window_bits: true}, offer() )
assertEqual( { client_max_window_bits: true }, offer() )
}})
describe("with an empty response", function() { with(this) {
@@ -63,21 +64,21 @@ test.describe("ClientSession", function() { with(this) {
it("uses context takeover and 15 window bits for inflating incoming messages", function() { with(this) {
activate()
expect(zlib, "createInflateRaw").given({windowBits: 15}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 15 }).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
it("uses context takeover and 15 window bits for deflating outgoing messages", function() { with(this) {
activate()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 15, level: level, memLevel: memLevel, strategy: strategy }).exactly(1).returning(deflate)
processOutgoingMessage()
processOutgoingMessage()
}})
}})
describe("when the response includes server_no_context_takeover", function() { with(this) {
define("response", {server_no_context_takeover: true})
define("response", { server_no_context_takeover: true })
it("accepts the response", function() { with(this) {
assertEqual( true, activate() )
@@ -85,15 +86,21 @@ test.describe("ClientSession", function() { with(this) {
it("ues no context takeover and 15 window bits for inflating incoming messages", function() { with(this) {
activate()
expect(zlib, "createInflateRaw").given({windowBits: 15}).exactly(2).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 15 }).exactly(2).returning(inflate)
expect(inflate, "close").exactly(2)
processIncomingMessage()
processIncomingMessage()
}})
it("catches errors thrown by zlib", function() { with(this) {
activate()
stub(zlib, "createInflateRaw").returning(inflate)
assertNothingThrown(function() { processIncomingMessage() })
}})
}})
describe("when the response includes client_no_context_takeover", function() { with(this) {
define("response", {client_no_context_takeover: true})
define("response", { client_no_context_takeover: true })
it("accepts the response", function() { with(this) {
assertEqual( true, activate() )
@@ -101,30 +108,36 @@ test.describe("ClientSession", function() { with(this) {
it("uses no context takeover and 15 window bits to deflate outgoing messages", function() { with(this) {
activate()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: level, memLevel: memLevel, strategy: strategy}).exactly(2).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 15, level: level, memLevel: memLevel, strategy: strategy }).exactly(2).returning(deflate)
expect(deflate, "close").exactly(2)
processOutgoingMessage()
processOutgoingMessage()
}})
it("catches errors thrown by zlib", function() { with(this) {
activate()
stub(zlib, "createDeflateRaw").returning(deflate)
assertNothingThrown(function() { processOutgoingMessage() })
}})
}})
describe("when the response includes server_max_window_bits", function() { with(this) {
define("response", {server_max_window_bits: 8})
define("response", { server_max_window_bits: 8 })
it("accepts the response", 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()
}})
}})
describe("when the response includes invalid server_max_window_bits", function() { with(this) {
define("response", {server_max_window_bits: 20})
define("response", { server_max_window_bits: 20 })
it("rejects the response", function() { with(this) {
assertEqual( false, activate() )
@@ -132,22 +145,22 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("when the response includes client_max_window_bits", function() { with(this) {
define("response", {client_max_window_bits: 8})
define("response", { client_max_window_bits: 8 })
it("accepts the response", 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()
}})
}})
describe("when the response includes invalid client_max_window_bits", function() { with(this) {
define("response", {client_max_window_bits: 20})
define("response", { client_max_window_bits: 20 })
it("rejects the response", function() { with(this) {
assertEqual( false, activate() )
@@ -156,10 +169,10 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with noContextTakeover", function() { with(this) {
define("options", {noContextTakeover: true})
define("options", { noContextTakeover: true })
it("sends client_no_context_takeover", function() { with(this) {
assertEqual( {client_no_context_takeover: true, client_max_window_bits: true}, offer() )
assertEqual( { client_no_context_takeover: true, client_max_window_bits: true }, offer() )
}})
describe("with an empty response", function() { with(this) {
@@ -169,7 +182,7 @@ test.describe("ClientSession", function() { with(this) {
it("uses no context takeover and 15 window bits for deflating outgoing messages", function() { with(this) {
activate()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: level, memLevel: memLevel, strategy: strategy}).exactly(2).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 15, level: level, memLevel: memLevel, strategy: strategy }).exactly(2).returning(deflate)
expect(deflate, "close").exactly(2)
processOutgoingMessage()
processOutgoingMessage()
@@ -178,10 +191,10 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with maxWindowBits", function() { with(this) {
define("options", {maxWindowBits: 9})
define("options", { maxWindowBits: 9 })
it("sends client_max_window_bits", function() { with(this) {
assertEqual( {client_max_window_bits: 9}, offer() )
assertEqual( { client_max_window_bits: 9 }, offer() )
}})
describe("with an empty response", function() { with(this) {
@@ -191,14 +204,14 @@ test.describe("ClientSession", function() { with(this) {
it("uses context takeover and 9 window bits for deflating outgoing messages", function() { with(this) {
activate()
expect(zlib, "createDeflateRaw").given({windowBits: 9, 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()
}})
}})
describe("when the response has higher client_max_window_bits", function() { with(this) {
define("response", {client_max_window_bits: 10})
define("response", { client_max_window_bits: 10 })
it("rejects the response", function() { with(this) {
assertEqual( false, activate() )
@@ -206,15 +219,15 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("when the response has lower client_max_window_bits", function() { with(this) {
define("response", {client_max_window_bits: 8});
define("response", { client_max_window_bits: 8 });
it("accepts the response", 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()
}})
@@ -222,7 +235,7 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with invalid maxWindowBits", function() { with(this) {
define("options", {maxWindowBits: 20})
define("options", { maxWindowBits: 20 })
it("throws when generating the offer", function() { with(this) {
assertThrows(Error, function() { offer() })
@@ -230,10 +243,10 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with requestNoContextTakeover", function() { with(this) {
define("options", {requestNoContextTakeover: true})
define("options", { requestNoContextTakeover: true })
it("sends server_no_context_takeover", function() { with(this) {
assertEqual( {client_max_window_bits: true, server_no_context_takeover: true}, offer() )
assertEqual( { client_max_window_bits: true, server_no_context_takeover: true }, offer() )
}})
describe("with an empty response", function() { with(this) {
@@ -243,7 +256,7 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("when the response includes server_no_context_takeover", function() { with(this) {
define("response", {server_no_context_takeover: true})
define("response", { server_no_context_takeover: true })
it("accepts the response", function() { with(this) {
assertEqual( true, activate() )
@@ -251,7 +264,7 @@ test.describe("ClientSession", function() { with(this) {
it("uses no context takeover and 15 window bits for inflating incoming messages", function() { with(this) {
activate()
expect(zlib, "createInflateRaw").given({windowBits: 15}).exactly(2).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 15 }).exactly(2).returning(inflate)
expect(inflate, "close").exactly(2)
processIncomingMessage()
processIncomingMessage()
@@ -260,10 +273,10 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with requestMaxWindowBits", function() { with(this) {
define("options", {requestMaxWindowBits: 12})
define("options", { requestMaxWindowBits: 12 })
it("sends server_max_window_bits", function() { with(this) {
assertEqual( { client_max_window_bits: true, server_max_window_bits: 12}, offer() )
assertEqual( { client_max_window_bits: true, server_max_window_bits: 12 }, offer() )
}})
describe("with an empty response", function() { with(this) {
@@ -273,7 +286,7 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("when the response has higher server_max_window_bits", function() { with(this) {
define("response", {server_max_window_bits: 13})
define("response", { server_max_window_bits: 13 })
it("rejects the response", function() { with(this) {
assertEqual( false, activate() )
@@ -281,7 +294,7 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("when the response has lower server_max_window_bits", function() { with(this) {
define("response", {server_max_window_bits: 11})
define("response", { server_max_window_bits: 11 })
it("accepts the response", function() { with(this) {
assertEqual( true, activate() )
@@ -289,7 +302,7 @@ test.describe("ClientSession", function() { with(this) {
it("uses context takeover and 11 window bits for inflating incoming messages", function() { with(this) {
activate()
expect(zlib, "createInflateRaw").given({windowBits: 11}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 11 }).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
@@ -297,7 +310,7 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with invalid requestMaxWindowBits", function() { with(this) {
define("options", {requestMaxWindowBits: 20})
define("options", { requestMaxWindowBits: 20 })
it("throws when generating the offer", function() { with(this) {
assertThrows(Error, function() { offer() })
@@ -305,31 +318,31 @@ 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()
}})
}})
describe("with memLevel", function() { with(this) {
define("options", {memLevel: 5})
define("options", { memLevel: 5 })
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()
}})
}})
+73 -60
View File
@@ -1,19 +1,20 @@
var PermessageDeflate = require('../lib/permessage_deflate'),
zlib = require('zlib'),
_zlib = require('zlib'),
test = require('jstest').Test
test.describe("ClientSession", function() { with(this) {
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.message = {data: "hello", rsv1: true}
this.ext = PermessageDeflate.configure(options)
this.zlib = {}
this.session = ext.configure({ zlib: zlib }).createServerSession([offer])
this.message = { data: "hello", rsv1: true }
}})
define("zlibMock", function() {
@@ -54,68 +55,80 @@ test.describe("ClientSession", function() { with(this) {
it("uses context takeover and 15 window bits for inflating incoming messages", function() { with(this) {
response()
expect(zlib, "createInflateRaw").given({windowBits: 15}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 15 }).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
it("uses context takeover and 15 window bits for deflating outgoing messages", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 15, level: level, memLevel: memLevel, strategy: strategy }).exactly(1).returning(deflate)
processOutgoingMessage()
processOutgoingMessage()
}})
}})
describe("when the offer includes server_no_context_takeover", function() { with(this) {
define("offer", {server_no_context_takeover: true})
define("offer", { server_no_context_takeover: true })
it("includes server_no_context_takeover in the response", function() { with(this) {
assertEqual( {server_no_context_takeover: true}, response() )
assertEqual( { server_no_context_takeover: true }, response() )
}})
it("uses no context takeover and 15 window bits for deflating outgoing messages", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: level, memLevel: memLevel, strategy: strategy}).exactly(2).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 15, level: level, memLevel: memLevel, strategy: strategy }).exactly(2).returning(deflate)
expect(deflate, "close").exactly(2)
processOutgoingMessage()
processOutgoingMessage()
}})
it("catches errors thrown by zlib", function() { with(this) {
response()
stub(zlib, "createDeflateRaw").returning(deflate)
assertNothingThrown(function() { processOutgoingMessage() })
}})
}})
describe("when the offer includes client_no_context_takeover", function() { with(this) {
define("offer", {client_no_context_takeover: true})
define("offer", { client_no_context_takeover: true })
it("includes client_no_context_takeover in the response", function() { with(this) {
assertEqual( {client_no_context_takeover: true}, response() )
assertEqual( { client_no_context_takeover: true }, response() )
}})
it("uses no context takeover and 15 window bits for inflating incoming messages", function() { with(this) {
response()
expect(zlib, "createInflateRaw").given({windowBits: 15}).exactly(2).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 15 }).exactly(2).returning(inflate)
expect(inflate, "close").exactly(2)
processIncomingMessage()
processIncomingMessage()
}})
it("catches errors thrown by zlib", function() { with(this) {
response()
stub(zlib, "createInflateRaw").returning(inflate)
assertNothingThrown(function() { processIncomingMessage() })
}})
}})
describe("when the offer includes server_max_window_bits", function() { with(this) {
define("offer", {server_max_window_bits: 13})
define("offer", { server_max_window_bits: 13 })
it("includes server_max_window_bits in the response", function() { with(this) {
assertEqual( {server_max_window_bits: 13}, response() )
assertEqual( { server_max_window_bits: 13 }, response() )
}})
it("uses context takeover and 13 window bits for deflating outgoing messages", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 13, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 13, level: level, memLevel: memLevel, strategy: strategy }).exactly(1).returning(deflate)
processOutgoingMessage()
processOutgoingMessage()
}})
}})
describe("when the offer includes invalid server_max_window_bits", function() { with(this) {
define("offer", {server_max_window_bits: 20})
define("offer", { server_max_window_bits: 20 })
it("does not create a session", function() { with(this) {
assertEqual( null, session )
@@ -123,7 +136,7 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("when the offer includes client_max_window_bits", function() { with(this) {
define("offer", {client_max_window_bits: true})
define("offer", { client_max_window_bits: true })
it("does not include a client_max_window_bits hint in the response", function() { with(this) {
assertEqual( {}, response() )
@@ -131,29 +144,29 @@ test.describe("ClientSession", function() { with(this) {
it("uses context takeover and 15 window bits for inflating incoming messages", function() { with(this) {
response()
expect(zlib, "createInflateRaw").given({windowBits: 15}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 15 }).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
}})
describe("when the offer includes a client_max_window_bits hint", function() { with(this) {
define("offer", {client_max_window_bits: 13})
define("offer", { client_max_window_bits: 13 })
it("includes a client_max_window_bits hint in the response", function() { with(this) {
assertEqual( {client_max_window_bits: 13}, response() )
assertEqual( { client_max_window_bits: 13 }, response() )
}})
it("uses context takeover and 13 window bits for inflating incoming messages", function() { with(this) {
response()
expect(zlib, "createInflateRaw").given({windowBits: 13}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 13 }).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
}})
describe("when the offer includes invalid client_max_window_bits", function() { with(this) {
define("offer", {client_max_window_bits: 20})
define("offer", { client_max_window_bits: 20 })
it("does not create a session", function() { with(this) {
assertEqual( null, session )
@@ -162,16 +175,16 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with noContextTakeover", function() { with(this) {
define("options", {noContextTakeover: true})
define("options", { noContextTakeover: true })
describe("with an empty offer", function() { with(this) {
it("includes server_no_context_takeover in the response", function() { with(this) {
assertEqual( {server_no_context_takeover: true}, response() )
assertEqual( { server_no_context_takeover: true }, response() )
}})
it("uses no context takeover and 15 window bits for deflating outgoing messages", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 15, level: level, memLevel: memLevel, strategy: strategy}).exactly(2).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 15, level: level, memLevel: memLevel, strategy: strategy }).exactly(2).returning(deflate)
expect(deflate, "close").exactly(2)
processOutgoingMessage()
processOutgoingMessage()
@@ -180,46 +193,46 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with maxWindowBits", function() { with(this) {
define("options", {maxWindowBits: 12})
define("options", { maxWindowBits: 12 })
describe("with an empty offer", function() { with(this) {
it("includes server_max_window_bits in the response", function() { with(this) {
assertEqual( {server_max_window_bits: 12}, response() )
it("does not include server_max_window_bits in the response", function() { with(this) {
assertEqual( {}, response() )
}})
it("uses context takeover and 12 window bits for deflating outgoing messages", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 12, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 12, level: level, memLevel: memLevel, strategy: strategy }).exactly(1).returning(deflate)
processOutgoingMessage()
processOutgoingMessage()
}})
}})
describe("when the offer has higher server_max_window_bits", function() { with(this) {
define("offer", {server_max_window_bits: 13})
define("offer", { server_max_window_bits: 13 })
it("includes server_max_window_bits in the response", function() { with(this) {
assertEqual( {server_max_window_bits: 12}, response() )
assertEqual( { server_max_window_bits: 12 }, response() )
}})
it("uses context takeover and 12 window bits for deflating outgoing messages", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 12, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 12, level: level, memLevel: memLevel, strategy: strategy }).exactly(1).returning(deflate)
processOutgoingMessage()
processOutgoingMessage()
}})
}})
describe("when the offer has lower server_max_window_bits", function() { with(this) {
define("offer", {server_max_window_bits: 11})
define("offer", { server_max_window_bits: 11 })
it("includes server_max_window_bits in the response", function() { with(this) {
assertEqual( {server_max_window_bits: 11}, response() )
assertEqual( { server_max_window_bits: 11 }, response() )
}})
it("uses context takeover and 11 window bits for deflating outgoing messages", function() { with(this) {
response()
expect(zlib, "createDeflateRaw").given({windowBits: 11, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
expect(zlib, "createDeflateRaw").given({ windowBits: 11, level: level, memLevel: memLevel, strategy: strategy }).exactly(1).returning(deflate)
processOutgoingMessage()
processOutgoingMessage()
}})
@@ -227,16 +240,16 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with requestNoContextTakeover", function() { with(this) {
define("options", {requestNoContextTakeover: true})
define("options", { requestNoContextTakeover: true })
describe("with an empty offer", function() { with(this) {
it("includes client_no_context_takeover in the response", function() { with(this) {
assertEqual( {client_no_context_takeover: true}, response() )
assertEqual( { client_no_context_takeover: true }, response() )
}})
it("uses no context takeover and 15 window bits for inflating incoming messages", function() { with(this) {
response()
expect(zlib, "createInflateRaw").given({windowBits: 15}).exactly(2).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 15 }).exactly(2).returning(inflate)
expect(inflate, "close").exactly(2)
processIncomingMessage()
processIncomingMessage()
@@ -245,7 +258,7 @@ test.describe("ClientSession", function() { with(this) {
}})
describe("with requestMaxWindowBits", function() { with(this) {
define("options", {requestMaxWindowBits: 11})
define("options", { requestMaxWindowBits: 11 })
describe("with an empty offer", function() { with(this) {
it("does not include client_max_window_bits in the response", function() { with(this) {
@@ -254,52 +267,52 @@ test.describe("ClientSession", function() { with(this) {
it("uses context takeover and 15 window bits for inflating incoming messages", function() { with(this) {
response()
expect(zlib, "createInflateRaw").given({windowBits: 15}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 15 }).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
}})
describe("when the offer includes client_max_window_bits", function() { with(this) {
define("offer", {client_max_window_bits: true})
define("offer", { client_max_window_bits: true })
it("includes client_max_window_bits in the response", function() { with(this) {
assertEqual( {client_max_window_bits: 11}, response() )
assertEqual( { client_max_window_bits: 11 }, response() )
}})
it("uses context takeover and 11 window bits for inflating incoming messages", function() { with(this) {
response()
expect(zlib, "createInflateRaw").given({windowBits: 11}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 11 }).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
}})
describe("when the offer has higher client_max_window_bits", function() { with(this) {
define("offer", {client_max_window_bits: 12})
define("offer", { client_max_window_bits: 12 })
it("includes client_max_window_bits in the response", function() { with(this) {
assertEqual( {client_max_window_bits: 11}, response() )
assertEqual( { client_max_window_bits: 11 }, response() )
}})
it("uses context takeover and 11 window bits for inflating incoming messages", function() { with(this) {
response()
expect(zlib, "createInflateRaw").given({windowBits: 11}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 11 }).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
}})
describe("when the offer has lower client_max_window_bits", function() { with(this) {
define("offer", {client_max_window_bits: 10})
define("offer", { client_max_window_bits: 10 })
it("includes client_max_window_bits in the response", function() { with(this) {
assertEqual( {client_max_window_bits: 10}, response() )
assertEqual( { client_max_window_bits: 10 }, response() )
}})
it("uses context takeover and 10 window bits for inflating incoming messages", function() { with(this) {
response()
expect(zlib, "createInflateRaw").given({windowBits: 10}).exactly(1).returning(inflate)
expect(zlib, "createInflateRaw").given({ windowBits: 10 }).exactly(1).returning(inflate)
processIncomingMessage()
processIncomingMessage()
}})
@@ -307,31 +320,31 @@ 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) {
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()
}})
}})
describe("with memLevel", function() { with(this) {
define("options", {memLevel: 5})
define("options", { memLevel: 5 })
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()
}})
}})