Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 913b174ea1 | |||
| 0eb99773db | |||
| 758ed46420 | |||
| 9cb62ecd49 | |||
| dca0a77b0d | |||
| 6e314bde56 | |||
| 47b3b3614b | |||
| 5da6a768b0 | |||
| f03aef1954 | |||
| adebc51630 | |||
| 958de927aa | |||
| 037afc350c | |||
| 10b5d6be57 | |||
| f48eaac6d3 | |||
| a71a06180a |
@@ -2,5 +2,6 @@
|
||||
.gitignore
|
||||
.npmignore
|
||||
.travis.yml
|
||||
examples
|
||||
node_modules
|
||||
spec
|
||||
|
||||
+7
-1
@@ -1,10 +1,16 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "0.6"
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
- "0.12"
|
||||
- "iojs-1"
|
||||
- "iojs-2"
|
||||
- "iojs-3"
|
||||
- "4"
|
||||
- "5"
|
||||
|
||||
before_install:
|
||||
- '[ "${TRAVIS_NODE_VERSION}" = "0.6" ] && npm conf set strict-ssl false || true'
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
### 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
|
||||
|
||||
### 0.1.2 / 2014-12-18
|
||||
|
||||
* 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
|
||||
|
||||
@@ -72,22 +72,21 @@ can be used to set the local session's behaviour and control that of the peer:
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 James Coglan
|
||||
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:
|
||||
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.
|
||||
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.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,52 @@
|
||||
var fs = require('fs'),
|
||||
deflate = require('..');
|
||||
|
||||
var records = fs.readFileSync(__dirname + '/bad.out.log', 'utf8')
|
||||
.replace(/\s*$/g, '')
|
||||
.split(/\n/)
|
||||
.map(JSON.parse);
|
||||
|
||||
var client = deflate.createClientSession(),
|
||||
offer = client.generateOffer(),
|
||||
server = deflate.createServerSession([offer]),
|
||||
response = server.generateResponse(),
|
||||
compressed = [],
|
||||
size = [0, 0];
|
||||
|
||||
client.activate(response);
|
||||
|
||||
function compress(index) {
|
||||
var record = records[index];
|
||||
if (!record) {
|
||||
console.log(size, size[0] / size[1]);
|
||||
return decompress(0);
|
||||
}
|
||||
|
||||
var message = {data: new Buffer(record[3], 'base64')};
|
||||
size[0] += message.data.length;
|
||||
|
||||
server.processOutgoingMessage(message, function(error, message) {
|
||||
compressed[index] = message;
|
||||
size[1] += message.data.length;
|
||||
compress(index + 1);
|
||||
});
|
||||
}
|
||||
|
||||
function decompress(index) {
|
||||
var record = records[index];
|
||||
if (!record) return;
|
||||
|
||||
var payload = record[3],
|
||||
message = compressed[index];
|
||||
|
||||
client.processIncomingMessage(message, function(error, message) {
|
||||
var output = message.data.toString('base64');
|
||||
if (output !== payload) {
|
||||
console.error('Failed on', record, message);
|
||||
process.exit(1);
|
||||
}
|
||||
decompress(index + 1);
|
||||
});
|
||||
}
|
||||
|
||||
compress(0);
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
+8
-1
@@ -8,7 +8,7 @@ var common = {
|
||||
'client_max_window_bits'
|
||||
],
|
||||
|
||||
DEFAULT_MAX_WINDOW_BITS: 15,
|
||||
MAX_WINDOW_BITS: 15,
|
||||
VALID_WINDOW_BITS: [8, 9, 10, 11, 12, 13, 14, 15],
|
||||
|
||||
concat: function(buffers, length) {
|
||||
@@ -29,6 +29,13 @@ var common = {
|
||||
return _default;
|
||||
},
|
||||
|
||||
validateOptions: function(options, validKeys) {
|
||||
for (var key in options) {
|
||||
if (validKeys.indexOf(key) < 0)
|
||||
throw new Error('Unrecognized option: ' + key);
|
||||
}
|
||||
},
|
||||
|
||||
validParams: function(params) {
|
||||
var keys = Object.keys(params), i = keys.length;
|
||||
while (i--) {
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
var ClientSession = require('./client_session'),
|
||||
ServerSession = require('./server_session');
|
||||
ServerSession = require('./server_session'),
|
||||
common = require('./common');
|
||||
|
||||
var VALID_OPTIONS = [
|
||||
'level',
|
||||
'memLevel',
|
||||
'strategy',
|
||||
'noContextTakeover',
|
||||
'maxWindowBits',
|
||||
'requestNoContextTakeover',
|
||||
'requestMaxWindowBits'
|
||||
];
|
||||
|
||||
var PermessageDeflate = {
|
||||
configure: function(options) {
|
||||
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}});
|
||||
|
||||
+27
-23
@@ -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;
|
||||
|
||||
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
|
||||
if (this._requestNoContextTakeover || this._params.client_no_context_takeover)
|
||||
params.client_no_context_takeover = true;
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
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/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;
|
||||
|
||||
+30
-16
@@ -3,8 +3,6 @@
|
||||
var zlib = require('zlib'),
|
||||
common = require('./common');
|
||||
|
||||
var VERSION = process.version.match(/\d+/g).map(function(n) { return parseInt(n, 10) });
|
||||
|
||||
var Session = function(options) {
|
||||
this._level = common.fetch(options, 'level', zlib.Z_DEFAULT_LEVEL);
|
||||
this._memLevel = common.fetch(options, 'memLevel', zlib.Z_DEFAULT_MEMLEVEL);
|
||||
@@ -90,19 +88,8 @@ Session.prototype.processOutgoingMessage = function(message, callback) {
|
||||
};
|
||||
|
||||
var onData = function(data) {
|
||||
var tail = data.slice(Math.max(data.length - 4, 0), data.length),
|
||||
isEnd = (tail[0] === 0x00 && tail[1] === 0x00 && tail[2] === 0xff && tail[3] === 0xff);
|
||||
|
||||
if (isEnd) data = data.slice(0, data.length - 4);
|
||||
|
||||
chunks.push(data);
|
||||
length += data.length;
|
||||
|
||||
if (isEnd) {
|
||||
message.rsv1 = true;
|
||||
message.data = common.concat(chunks, length);
|
||||
return_(null, message);
|
||||
}
|
||||
};
|
||||
|
||||
var onError = function(error) {
|
||||
@@ -111,9 +98,19 @@ Session.prototype.processOutgoingMessage = function(message, callback) {
|
||||
|
||||
deflate.on('data', onData);
|
||||
deflate.on('error', onError);
|
||||
|
||||
deflate.write(message.data);
|
||||
if (VERSION[0] === 0 && VERSION[1] < 10) deflate.flush();
|
||||
|
||||
var onFlush = function() {
|
||||
var data = common.concat(chunks, length);
|
||||
message.data = data.slice(0, data.length - 4);
|
||||
message.rsv1 = true;
|
||||
return_(null, message);
|
||||
};
|
||||
|
||||
if (deflate.params !== undefined)
|
||||
deflate.flush(zlib.Z_SYNC_FLUSH, onFlush);
|
||||
else
|
||||
deflate.flush(onFlush);
|
||||
};
|
||||
|
||||
Session.prototype.close = function() {
|
||||
@@ -135,12 +132,29 @@ Session.prototype._getDeflate = function() {
|
||||
if (this._deflate) return this._deflate;
|
||||
|
||||
var deflate = zlib.createDeflateRaw({
|
||||
flush: zlib.Z_SYNC_FLUSH,
|
||||
windowBits: this._ownWindowBits,
|
||||
level: this._level,
|
||||
memLevel: this._memLevel,
|
||||
strategy: this._strategy
|
||||
});
|
||||
|
||||
var flush = deflate.flush;
|
||||
|
||||
// This monkey-patch is needed to make Node 0.10 produce optimal output.
|
||||
// Without this it uses Z_FULL_FLUSH and effectively drops all its context
|
||||
// state on every flush.
|
||||
|
||||
if (deflate._flushFlag !== undefined && deflate.params === undefined)
|
||||
deflate.flush = function(callback) {
|
||||
var ws = this._writableState;
|
||||
if (ws.ended || ws.ending || ws.needDrain) {
|
||||
flush.call(this, callback);
|
||||
} else {
|
||||
this._flushFlag = zlib.Z_SYNC_FLUSH;
|
||||
this.write(new Buffer(0), '', callback);
|
||||
}
|
||||
};
|
||||
|
||||
if (this._ownContextTakeover) this._deflate = deflate;
|
||||
return deflate;
|
||||
};
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
, "keywords" : ["websocket", "compression", "deflate"]
|
||||
, "license" : "MIT"
|
||||
|
||||
, "version" : "0.1.1"
|
||||
, "version" : "0.1.4"
|
||||
, "engines" : {"node": ">=0.6.0"}
|
||||
, "main" : "./lib/permessage_deflate"
|
||||
, "devDependencies" : {"jstest": ""}
|
||||
|
||||
+10
-11
@@ -9,7 +9,6 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
this.deflate = zlibMock()
|
||||
this.inflate = zlibMock()
|
||||
this.flush = zlib.Z_SYNC_FLUSH
|
||||
this.level = zlib.Z_DEFAULT_LEVEL
|
||||
this.memLevel = zlib.Z_DEFAULT_MEMLEVEL
|
||||
this.strategy = zlib.Z_DEFAULT_STRATEGY
|
||||
@@ -25,7 +24,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
this.stub(stream, "removeListener")
|
||||
|
||||
this.stub(stream, "write")
|
||||
this.stub(stream, "flush", function(cb) { if(cb) cb() });
|
||||
this.stub(stream, "flush").yields([])
|
||||
this.stub(stream, "close").raises(new Error("unexpected close()"))
|
||||
|
||||
return stream
|
||||
@@ -71,7 +70,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("uses context takeover and 15 window bits for deflating outgoing messages", function() { with(this) {
|
||||
activate()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
@@ -102,7 +101,7 @@ 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({flush: flush, 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()
|
||||
@@ -141,7 +140,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("uses context takeover and 8 window bits for deflating outgoing messages", function() { with(this) {
|
||||
activate()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, windowBits: 8, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
|
||||
expect(zlib, "createDeflateRaw").given({windowBits: 8, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
|
||||
processOutgoingMessage()
|
||||
processOutgoingMessage()
|
||||
}})
|
||||
@@ -170,7 +169,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({flush: flush, 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()
|
||||
@@ -192,7 +191,7 @@ 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({flush: flush, 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()
|
||||
}})
|
||||
@@ -215,7 +214,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("uses context takeover and 8 window bits for deflating outgoing messages", function() { with(this) {
|
||||
activate()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, windowBits: 8, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
|
||||
expect(zlib, "createDeflateRaw").given({windowBits: 8, level: level, memLevel: memLevel, strategy: strategy}).exactly(1).returning(deflate)
|
||||
processOutgoingMessage()
|
||||
processOutgoingMessage()
|
||||
}})
|
||||
@@ -310,7 +309,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("sets the level of the deflate stream", function() { with(this) {
|
||||
activate()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
}})
|
||||
@@ -320,7 +319,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("sets the memLevel of the deflate stream", function() { with(this) {
|
||||
activate()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
}})
|
||||
@@ -330,7 +329,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("sets the strategy of the deflate stream", function() { with(this) {
|
||||
activate()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
}})
|
||||
|
||||
+14
-15
@@ -2,14 +2,13 @@ var PermessageDeflate = require('../lib/permessage_deflate'),
|
||||
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.flush = zlib.Z_SYNC_FLUSH
|
||||
this.level = zlib.Z_DEFAULT_LEVEL
|
||||
this.memLevel = zlib.Z_DEFAULT_MEMLEVEL
|
||||
this.strategy = zlib.Z_DEFAULT_STRATEGY
|
||||
@@ -25,7 +24,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
this.stub(stream, "removeListener")
|
||||
|
||||
this.stub(stream, "write")
|
||||
this.stub(stream, "flush", function(cb) { if(cb) cb() });
|
||||
this.stub(stream, "flush").yields([])
|
||||
this.stub(stream, "close").raises(new Error("unexpected close()"))
|
||||
|
||||
return stream
|
||||
@@ -62,7 +61,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("uses context takeover and 15 window bits for deflating outgoing messages", function() { with(this) {
|
||||
response()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
@@ -77,7 +76,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("uses no context takeover and 15 window bits for deflating outgoing messages", function() { with(this) {
|
||||
response()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
@@ -109,7 +108,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("uses context takeover and 13 window bits for deflating outgoing messages", function() { with(this) {
|
||||
response()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
@@ -172,7 +171,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("uses no context takeover and 15 window bits for deflating outgoing messages", function() { with(this) {
|
||||
response()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
@@ -184,13 +183,13 @@ test.describe("ClientSession", function() { with(this) {
|
||||
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({flush: flush, 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()
|
||||
}})
|
||||
@@ -205,7 +204,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("uses context takeover and 12 window bits for deflating outgoing messages", function() { with(this) {
|
||||
response()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
@@ -220,7 +219,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("uses context takeover and 11 window bits for deflating outgoing messages", function() { with(this) {
|
||||
response()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
@@ -312,7 +311,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("sets the level of the deflate stream", function() { with(this) {
|
||||
response()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
}})
|
||||
@@ -322,7 +321,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("sets the memLevel of the deflate stream", function() { with(this) {
|
||||
response()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
}})
|
||||
@@ -332,7 +331,7 @@ test.describe("ClientSession", function() { with(this) {
|
||||
|
||||
it("sets the strategy of the deflate stream", function() { with(this) {
|
||||
response()
|
||||
expect(zlib, "createDeflateRaw").given({flush: flush, 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()
|
||||
}})
|
||||
}})
|
||||
|
||||
Reference in New Issue
Block a user