http2-protocol
Advanced tools
Comparing version 0.12.0 to 0.12.1
Version history | ||
=============== | ||
### 0.12.1 (2014-04-26) ### | ||
* Support for sending BLOCKED frame | ||
### 0.12.0 (2014-04-24) ### | ||
@@ -5,0 +9,0 @@ |
@@ -67,2 +67,3 @@ var assert = require('assert'); | ||
this._received = 0; | ||
this._blocked = false; | ||
} | ||
@@ -110,2 +111,3 @@ Flow.prototype = Object.create(Duplex.prototype, { constructor: { value: Flow } }); | ||
// a WINDOW_UPDATE that restores the flow control window of the remote end. | ||
// TODO: push this directly into the output queue. No need to wait for DATA frames in the queue. | ||
Flow.prototype._restoreWindow = function _restoreWindow() { | ||
@@ -159,2 +161,3 @@ delete this._restoreWindowTimer; | ||
else if (this._window > 0) { | ||
this._blocked = false; | ||
this._readableState.sync = true; // to avoid reentrant calls | ||
@@ -175,4 +178,10 @@ do { | ||
// * otherwise, come back when the flow control window is positive | ||
else { | ||
else if (!this._blocked) { | ||
this._parentPush({ | ||
type: 'BLOCKED', | ||
flags: {}, | ||
stream: this._flowControlId | ||
}) | ||
this.once('window_update', this._read); | ||
this._blocked = true; | ||
} | ||
@@ -179,0 +188,0 @@ }; |
{ | ||
"name": "http2-protocol", | ||
"version": "0.12.0", | ||
"version": "0.12.1", | ||
"description": "A JavaScript implementation of the HTTP/2 framing layer", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -53,8 +53,8 @@ node-http2-protocol | ||
To generate a code coverage report, run `npm test --coverage` (it may be slow, be patient). | ||
Code coverage summary as of version 0.12.0: | ||
Code coverage summary as of version 0.12.1: | ||
``` | ||
Statements : 91.6% ( 1352/1476 ) | ||
Branches : 85.15% ( 562/660 ) | ||
Statements : 91.63% ( 1357/1481 ) | ||
Branches : 85.2% ( 564/662 ) | ||
Functions : 92.5% ( 148/160 ) | ||
Lines : 91.69% ( 1346/1468 ) | ||
Lines : 91.72% ( 1351/1473 ) | ||
``` | ||
@@ -61,0 +61,0 @@ |
@@ -6,2 +6,4 @@ var expect = require('chai').expect; | ||
var MAX_PAYLOAD_SIZE = 4096; | ||
function createFlow(log) { | ||
@@ -47,2 +49,3 @@ var flowControlId = util.random(10, 100); | ||
flow._queue.push({ type: 'DATA', flags: {}, data: { length: 1 } }); | ||
expect(flow.read().type).to.equal('BLOCKED'); | ||
expect(flow.read()).to.equal(null); | ||
@@ -180,2 +183,3 @@ | ||
if (frame.type === 'DATA') { | ||
expect(frame.data.length).to.be.lte(MAX_PAYLOAD_SIZE) | ||
output.push(frame.data); | ||
@@ -203,3 +207,61 @@ } | ||
}); | ||
describe('when running out of window', function() { | ||
it('should send a BLOCKED frame', function(done) { | ||
// Sender side | ||
console.log(flow1._flowControlId, flow2._flowControlId) | ||
var frameNumber = util.random(5, 8); | ||
var input = []; | ||
flow1._send = function _send() { | ||
if (input.length >= frameNumber) { | ||
this.push({ type: 'DATA', flags: { END_STREAM: true }, data: new Buffer(0) }); | ||
this.push(null); | ||
} else { | ||
var buffer = new Buffer(util.random(1000, 100000)); | ||
input.push(buffer); | ||
this.push({ type: 'DATA', flags: {}, data: buffer }); | ||
} | ||
}; | ||
// Receiver side | ||
// Do not send WINDOW_UPDATESs except when the other side sends BLOCKED | ||
var output = []; | ||
flow2._restoreWindow = util.noop; | ||
flow2._receive = function _receive(frame, callback) { | ||
if (frame.type === 'DATA') { | ||
expect(frame.data.length).to.be.lte(MAX_PAYLOAD_SIZE) | ||
output.push(frame.data); | ||
} | ||
if (frame.flags.END_STREAM) { | ||
this.emit('end_stream'); | ||
} | ||
if (frame.type === 'BLOCKED') { | ||
setTimeout(function() { | ||
this._push({ | ||
type: 'WINDOW_UPDATE', | ||
flags: {}, | ||
stream: this._flowControlId, | ||
window_size: this._received | ||
}); | ||
this._received = 0; | ||
}.bind(this), 20); | ||
} | ||
callback(); | ||
}; | ||
// Checking results | ||
flow2.on('end_stream', function() { | ||
input = util.concat(input); | ||
output = util.concat(output); | ||
expect(input).to.deep.equal(output); | ||
done(); | ||
}); | ||
// Start piping | ||
flow1.pipe(flow2).pipe(flow1); | ||
}) | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
247736
5782