Skip to content

Commit

Permalink
Ensure trailers get the END_STREAM flag. Release v3.3.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
nwgh committed Feb 16, 2018
1 parent f3189f3 commit c0fde18
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Version history
===============

### 3.3.8 (2018-02-15) ###
* Fix an issue with HTTP trailers and END_STREAM.

### 3.3.7 (2017-09-21) ###
* Mark as incompatible with node >= 9.0.0 (to encourage using the built-in http2 module available by default in node >= 9.0.0).

Expand Down
2 changes: 1 addition & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ OutgoingMessage.prototype._finish = function _finish() {
if (this.request) {
this.request.addTrailers(this._trailers);
} else {
this.stream.headers(this._trailers);
this.stream.trailers(this._trailers);
}
}
this.finished = true;
Expand Down
18 changes: 18 additions & 0 deletions lib/protocol/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function Stream(log, connection) {
this._initializeState();

this.connection = connection;
this.sentEndStream = false;
}

Stream.prototype = Object.create(Duplex.prototype, { constructor: { value: Stream } });
Expand Down Expand Up @@ -106,6 +107,16 @@ Stream.prototype.headers = function headers(headers) {
});
};

Stream.prototype.trailers = function trailers(trailers) {
this.sentEndStream = true;
this._pushUpstream({
type: 'HEADERS',
flags: {'END_STREAM': true},
stream: this.id,
headers: trailers
});
};

Stream.prototype._onHeaders = function _onHeaders(frame) {
if (frame.priority !== undefined) {
this.priority(frame.priority, true);
Expand Down Expand Up @@ -342,6 +353,13 @@ Stream.prototype._finishing = function _finishing() {
stream: this.id,
data: emptyBuffer
};

if (this.sentEndStream) {
this._log.debug('Already sent END_STREAM, not sending again.');
return;
}

this.sentEndStream = true;
var lastFrame = this.upstream.getLastQueuedFrame();
if (lastFrame && ((lastFrame.type === 'DATA') || (lastFrame.type === 'HEADERS'))) {
this._log.debug({ frame: lastFrame }, 'Marking last frame with END_STREAM flag.');
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "http2",
"version": "3.3.7",
"version": "3.3.8",
"description": "An HTTP/2 client and server implementation",
"main": "lib/index.js",
"engines" : {
"node" : ">=0.12.0 <9.0.0"
"engines": {
"node": ">=0.12.0 <9.0.0"
},
"devDependencies": {
"istanbul": "*",
Expand Down

0 comments on commit c0fde18

Please sign in to comment.