Bug 1429973 part 0 - Update node-http2 to v3.3.8 for required bugfix. r=bagder
authorNicholas Hurley <hurley@mozilla.com>
Thu, 15 Feb 2018 10:12:38 -0800
changeset 444446 8438cc4db7709b106a68a392bef840a504eeea7d
parent 444445 8c0beb6eb43a3396ce92cfeb5f9f174372b9de1a
child 444447 446096b9960dd7bcd41e2cd8130e3c1156a939a9
push idunknown
push userunknown
push dateunknown
reviewersbagder
bugs1429973
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1429973 part 0 - Update node-http2 to v3.3.8 for required bugfix. r=bagder MozReview-Commit-ID: 60AQesLEA3K
testing/xpcshell/node-http2/HISTORY.md
testing/xpcshell/node-http2/README.md
testing/xpcshell/node-http2/lib/http.js
testing/xpcshell/node-http2/lib/protocol/flow.js
testing/xpcshell/node-http2/lib/protocol/stream.js
testing/xpcshell/node-http2/package.json
testing/xpcshell/node-http2/test/flow.js
testing/xpcshell/node-http2/test/stream.js
--- a/testing/xpcshell/node-http2/HISTORY.md
+++ b/testing/xpcshell/node-http2/HISTORY.md
@@ -1,11 +1,17 @@
 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).
+
 ### 3.3.6 (2016-09-16) ###
 * We were not appropriately sending HPACK context updates when receiving SETTINGS_HEADER_TABLE_SIZE. This release fixes that bug.
 
 ### 3.3.5 (2016-09-06) ###
 * Fix issues with large DATA frames (https://github.com/molnarg/node-http2/issues/207)
 
 ### 3.3.4 (2016-04-22) ###
 * More PR bugfixes (https://github.com/molnarg/node-http2/issues?q=milestone%3Av3.3.4)
--- a/testing/xpcshell/node-http2/README.md
+++ b/testing/xpcshell/node-http2/README.md
@@ -1,16 +1,18 @@
 node-http2
 ==========
 
 An HTTP/2 ([RFC 7540](http://tools.ietf.org/html/rfc7540))
 client and server implementation for node.js.
 
 ![Travis CI status](https://travis-ci.org/molnarg/node-http2.svg?branch=master)
 
+**NOTE WELL** This package is officially deprecated. As of node 9.0.0, there is an 'http2' package built-in. You should use that one instead.
+
 Installation
 ------------
 
 ```
 npm install http2
 ```
 
 API
--- a/testing/xpcshell/node-http2/lib/http.js
+++ b/testing/xpcshell/node-http2/lib/http.js
@@ -340,32 +340,32 @@ OutgoingMessage.prototype._write = funct
 };
 
 OutgoingMessage.prototype._finish = function _finish() {
   if (this.stream) {
     if (this._trailers) {
       if (this.request) {
         this.request.addTrailers(this._trailers);
       } else {
-        this.stream.headers(this._trailers);
+        this.stream.trailers(this._trailers);
       }
     }
     this.finished = true;
     this.stream.end();
   } else {
     this.once('socket', this._finish.bind(this));
   }
 };
 
 OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
   if (this.headersSent) {
     return this.emit('error', new Error('Can\'t set headers after they are sent.'));
   } else {
     name = name.toLowerCase();
-    if (deprecatedHeaders.includes(name)) {
+    if (deprecatedHeaders.indexOf(name) !== -1) {
       return this.emit('error', new Error('Cannot set deprecated header: ' + name));
     }
     this._headers[name] = value;
   }
 };
 
 OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
   if (this.headersSent) {
--- a/testing/xpcshell/node-http2/lib/protocol/flow.js
+++ b/testing/xpcshell/node-http2/lib/protocol/flow.js
@@ -82,23 +82,23 @@ Flow.prototype._receive = function _rece
 Flow.prototype._write = function _write(frame, encoding, callback) {
   var sentToUs = (this._flowControlId === undefined) || (frame.stream === this._flowControlId);
 
   if (sentToUs && (frame.flags.END_STREAM || (frame.type === 'RST_STREAM'))) {
     this._ended = true;
   }
 
   if ((frame.type === 'DATA') && (frame.data.length > 0)) {
-    this._receive(frame, () => {
+    this._receive(frame, function() {
       this._received += frame.data.length;
       if (!this._restoreWindowTimer) {
         this._restoreWindowTimer = setImmediate(this._restoreWindow.bind(this));
       }
       callback();
-    });
+    }.bind(this));
   }
 
   else {
     this._receive(frame, callback);
   }
 
   if (sentToUs && (frame.type === 'WINDOW_UPDATE')) {
     this._updateWindow(frame);
--- a/testing/xpcshell/node-http2/lib/protocol/stream.js
+++ b/testing/xpcshell/node-http2/lib/protocol/stream.js
@@ -57,16 +57,17 @@ function Stream(log, connection) {
 
   // * sending and receiving frames to/from the upstream connection
   this._initializeDataFlow();
 
   // * maintaining the state of the stream (idle, open, closed, etc.) and error detection
   this._initializeState();
 
   this.connection = connection;
+  this.sentEndStream = false;
 }
 
 Stream.prototype = Object.create(Duplex.prototype, { constructor: { value: Stream } });
 
 // Managing the stream
 // -------------------
 
 // the default stream priority is 2^30
@@ -101,16 +102,26 @@ Stream.prototype.headers = function head
   this._pushUpstream({
     type: 'HEADERS',
     flags: {},
     stream: this.id,
     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);
   }
   this.emit('headers', frame.headers);
 };
 
 Stream.prototype.priority = function priority(priority, peer) {
@@ -337,16 +348,23 @@ Stream.prototype._send = function _send(
 var emptyBuffer = new Buffer(0);
 Stream.prototype._finishing = function _finishing() {
   var endFrame = {
     type: 'DATA',
     flags: { END_STREAM: true },
     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.');
     lastFrame.flags.END_STREAM = true;
     this._transition(true, endFrame);
   } else {
     this._pushUpstream(endFrame);
   }
--- a/testing/xpcshell/node-http2/package.json
+++ b/testing/xpcshell/node-http2/package.json
@@ -1,15 +1,15 @@
 {
   "name": "http2",
-  "version": "3.3.6",
+  "version": "3.3.8",
   "description": "An HTTP/2 client and server implementation",
   "main": "lib/index.js",
-  "engines" : {
-    "node" : ">=0.12.0"
+  "engines": {
+    "node": ">=0.12.0 <9.0.0"
   },
   "devDependencies": {
     "istanbul": "*",
     "chai": "*",
     "mocha": "*",
     "docco": "*",
     "bunyan": "*"
   },
--- a/testing/xpcshell/node-http2/test/flow.js
+++ b/testing/xpcshell/node-http2/test/flow.js
@@ -224,25 +224,25 @@ describe('flow.js', function() {
           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(() => {
+            setTimeout(function() {
               this._push({
                 type: 'WINDOW_UPDATE',
                 flags: {},
                 stream: this._flowControlId,
                 window_size: this._received
               });
               this._received = 0;
-            }, 20);
+            }.bind(this), 20);
           }
           callback();
         };
 
         // Checking results
         flow2.on('end_stream', function() {
           input = util.concat(input);
           output = util.concat(output);
--- a/testing/xpcshell/node-http2/test/stream.js
+++ b/testing/xpcshell/node-http2/test/stream.js
@@ -18,17 +18,17 @@ function execute_sequence(stream, sequen
     sequence = stream;
     stream = createStream();
   }
 
   var outgoing_frames = [];
 
   var emit = stream.emit, events = [];
   stream.emit = function(name) {
-    if (recorded_events.includes(name)) {
+    if (recorded_events.indexOf(name) !== -1) {
       events.push({ name: name, data: Array.prototype.slice.call(arguments, 1) });
     }
     return emit.apply(this, arguments);
   };
 
   var commands = [], checks = [];
   sequence.forEach(function(step) {
     if ('method' in step || 'incoming' in step || 'outgoing' in step || 'wait' in step || 'set_state' in step) {