h2lean 0.9.1 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/compat.js +28 -0
- package/lib/session.js +24 -0
- package/lib/stream.js +2071 -167
- package/package.json +1 -1
package/lib/compat.js
CHANGED
|
@@ -619,6 +619,15 @@ class Http2ServerResponse extends Stream {
|
|
|
619
619
|
|
|
620
620
|
setTrailer(name, value) {
|
|
621
621
|
checkName(name);
|
|
622
|
+
// node's setTrailer has no end() guard (internal/http2/compat.js:580) -- trailers
|
|
623
|
+
// added after end() but before the 'wantTrailers' tick reach the wire there,
|
|
624
|
+
// because nghttp2 withholds END_STREAM while waitForTrailers is set. The staged
|
|
625
|
+
// fast path must recall its frame so the same shape holds here (item 44); after
|
|
626
|
+
// the flush the frame is gone and the trailer is lost on node too, its tick
|
|
627
|
+
// having already answered the empty block.
|
|
628
|
+
if (this._stream._esStaged) {
|
|
629
|
+
this._stream._recallStagedEnd();
|
|
630
|
+
}
|
|
622
631
|
this._trailers[trimName(name)] = value;
|
|
623
632
|
}
|
|
624
633
|
|
|
@@ -811,6 +820,25 @@ class Http2ServerResponse extends Stream {
|
|
|
811
820
|
// END_STREAM), the recorded fields when it added some. Calling sendTrailers() here
|
|
812
821
|
// instead put the block in front of that machinery -- and threw NOT_READY as soon as
|
|
813
822
|
// sendTrailers() grew node's own trailersReady guard.
|
|
823
|
+
let recorded = false;
|
|
824
|
+
for (const key in this._trailers) {
|
|
825
|
+
if (Object.prototype.hasOwnProperty.call(this._trailers, key)) {
|
|
826
|
+
recorded = true;
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
// The trailer-less response -- the shape of every response that never called
|
|
831
|
+
// addTrailers -- stages its END_STREAM inside the read batch instead of from the
|
|
832
|
+
// tick (item 44). The event path is untouched: _waitForTrailers stays set and the
|
|
833
|
+
// tick still fires 'wantTrailers', where sendTrailers closes the stream without
|
|
834
|
+
// staging the frame twice. A body parked on window credit, a refused block and a
|
|
835
|
+
// HEAD-request close keep the deferred path -- the staged frame would land before
|
|
836
|
+
// the queued DATA, and the refused shape records the end without wire work.
|
|
837
|
+
if (!recorded && stream._waitForTrailers && stream._queued === null &&
|
|
838
|
+
!stream._blockRefused) {
|
|
839
|
+
stream.endWithStagedEnd();
|
|
840
|
+
return this;
|
|
841
|
+
}
|
|
814
842
|
stream.end();
|
|
815
843
|
return this;
|
|
816
844
|
}
|
package/lib/session.js
CHANGED
|
@@ -1414,6 +1414,28 @@ class Http2Session extends EventEmitter {
|
|
|
1414
1414
|
}
|
|
1415
1415
|
}
|
|
1416
1416
|
|
|
1417
|
+
// Remove a not-yet-committed END_STREAM frame that _frame staged for sid, the
|
|
1418
|
+
// stage-form half of the pushStream cut above: the frame has not left in a batch,
|
|
1419
|
+
// so a trailer added after end() can supersede it (stream._recallStagedEnd). False
|
|
1420
|
+
// when there is no marker, or the frame already moved into the queue or onto the
|
|
1421
|
+
// wire -- past that point the octets are gone and the caller keeps its state.
|
|
1422
|
+
// While stream._esStaged is set the marker is always in the stage form: the frame
|
|
1423
|
+
// is staged by compat's end(), whose caller may only run its own synchronous turn
|
|
1424
|
+
// and nextTicks before the 'wantTrailers' tick -- write() after end() throws and
|
|
1425
|
+
// pushStream cuts its own END_STREAM -- and the flush that would commit the stage
|
|
1426
|
+
// is a microtask behind both of those.
|
|
1427
|
+
_cutStagedES(sid) {
|
|
1428
|
+
const es = this._esMarkers.get(sid);
|
|
1429
|
+
if (es === undefined || !es.stage) {
|
|
1430
|
+
return false;
|
|
1431
|
+
}
|
|
1432
|
+
this._esMarkers.delete(sid);
|
|
1433
|
+
this._stage.copyWithin(es.off, es.off + es.len, this._stageLen);
|
|
1434
|
+
this._stageLen -= es.len;
|
|
1435
|
+
this._outLen -= es.len;
|
|
1436
|
+
return true;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1417
1439
|
// Writes DATA within the stream and connection windows. Returns true when
|
|
1418
1440
|
// everything went out; false means the caller should wait for WINDOW_UPDATE.
|
|
1419
1441
|
sendData(stream, buf, end) {
|
|
@@ -3017,6 +3039,8 @@ class Http2Session extends EventEmitter {
|
|
|
3017
3039
|
q.shift();
|
|
3018
3040
|
}
|
|
3019
3041
|
stream._queued = null;
|
|
3042
|
+
// the credit stall that set the Duplex needDrain report is over
|
|
3043
|
+
stream._needDrain = false;
|
|
3020
3044
|
this._blocked.delete(stream);
|
|
3021
3045
|
this.state.outboundQueueSize = this._blocked.size;
|
|
3022
3046
|
// A trailer block stashed by sendTrailers() belongs after the body it follows, and it
|