6 Commits

10 changed files with 5913 additions and 32 deletions
+1
View File
@@ -2,5 +2,6 @@
.gitignore
.npmignore
.travis.yml
examples
node_modules
spec
+6 -1
View File
@@ -1,3 +1,4 @@
sudo: false
language: node_js
node_js:
@@ -5,7 +6,11 @@ node_js:
- "0.8"
- "0.10"
- "0.12"
- "iojs"
- "iojs-1"
- "iojs-2"
- "iojs-3"
- "4"
- "5"
before_install:
- '[ "${TRAVIS_NODE_VERSION}" = "0.6" ] && npm conf set strict-ssl false || true'
+10
View File
@@ -1,3 +1,13 @@
### 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
+5809
View File
File diff suppressed because it is too large Load Diff
+52
View File
@@ -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);
+3 -3
View File
@@ -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;
};
+1 -1
View File
@@ -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) {
+27 -23
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;
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;
+1 -1
View File
@@ -5,7 +5,7 @@
, "keywords" : ["websocket", "compression", "deflate"]
, "license" : "MIT"
, "version" : "0.1.2"
, "version" : "0.1.4"
, "engines" : {"node": ">=0.6.0"}
, "main" : "./lib/permessage_deflate"
, "devDependencies" : {"jstest": ""}
+3 -3
View File
@@ -2,7 +2,7 @@ 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])
@@ -183,8 +183,8 @@ 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) {