h2lean 0.18.0 → 0.18.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/headers.js CHANGED
@@ -670,9 +670,12 @@ let hitPlan = null;
670
670
  // OPTIMIZATION.md item 68.
671
671
  function prepare(headers, opts, session) {
672
672
  const sendDate = !!(opts && opts.sendDate);
673
+ const request = !!(opts && opts.request);
673
674
  const enc = session._encoder;
674
675
  const stamp = sendDate ? touchDate() : -1;
675
- const cacheable = Object.isFrozen(headers) && enc.pendingSize === null;
676
+ // A PUSH_PROMISE is one-shot: node never caches its block, and the request
677
+ // pseudo-headers would otherwise share a cache key with a response's map.
678
+ const cacheable = Object.isFrozen(headers) && enc.pendingSize === null && !request;
676
679
  if (cacheable) {
677
680
  const hit = session._blocks.get(headers);
678
681
  if (hit !== undefined && hit.epoch === enc.epoch && hit.stamp === stamp) {
@@ -690,7 +693,7 @@ function prepare(headers, opts, session) {
690
693
  }
691
694
  const parsed = parse(headers,
692
695
  { trailer: !!(opts && opts.trailer), sendDate, info: !!(opts && opts.info),
693
- strict: session._strictSingle });
696
+ request, strict: session._strictSingle });
694
697
  sent.status = parsed.status;
695
698
  sent.date = parsed.genDate;
696
699
  // The size update is NOT consumed here: writePrepared() writes its octets into the
@@ -1841,78 +1841,55 @@ class Http2ServerSession extends EventEmitter {
1841
1841
  }
1842
1842
 
1843
1843
  // Returns true when the block was refused, so the caller knows the wire state its
1844
- // HEADERS would have advanced never happened (see _blockRefused in lib/server/Http2ServerStream.js).
1845
- sendHeaders(sid, block, end, bound) {
1846
- // nghttp2 refuses an outbound header block whose estimate exceeds the session's
1847
- // maxSendHeaderBlockLength, and it does so at *prep* time -- after the JS call that
1848
- // submitted it returned (nghttp2_session.c, the NGHTTP2_HEADERS case of
1849
- // session_prep_frame). So this is not a throw: node emits 'frameError' on the stream
1850
- // and closes both it and the session a turn later (onFrameError,
1851
- // internal/http2/core.js). Measured on v26.12.1 for an oversize trailer block:
1852
- // frameError(1, 6, sid), ERR_HTTP2_STREAM_ERROR naming NGHTTP2_FRAME_SIZE_ERROR,
1853
- // rstCode 6, and RST_STREAM(6) then GOAWAY(0) on the wire.
1854
- if (bound + PRIORITY_SPECLEN > this._maxSendBlock) {
1855
- this._refuseBlock(sid, HEADERS);
1856
- return true;
1857
- }
1858
- this.state.deflateDynamicTableSize = this._encoder.size;
1859
- const max = this.remoteSettings.maxFrameSize;
1860
- // END_STREAM rides on the HEADERS frame even when CONTINUATION frames follow it:
1861
- // RFC 9113 6.2 ("a HEADERS frame with the END_STREAM flag set can be followed by
1862
- // CONTINUATION frames ... logically, the CONTINUATION frames are part of the HEADERS
1863
- // frame"), 5.1 ("CONTINUATION frames do not result in state transitions") and 8.1,
1864
- // which says it outright for trailers -- "a sequence starting with a HEADERS frame,
1865
- // followed by zero or more CONTINUATION frames, where the HEADERS frame bears an
1866
- // END_STREAM flag". Measured on node's wire for a trailer block over one frame:
1867
- // HEADERS flags 0x1 len 16384, CONTINUATION flags 0x4. On the last CONTINUATION
1868
- // instead, node's client answers ERR_HTTP2_STREAM_ERROR / rstCode 1 and h2lean's own
1869
- // receiver -- which reads the flag off HEADERS -- never sees the message end.
1870
- const es = end ? F_END_STREAM : 0;
1871
- if (block.length <= max) {
1872
- this._frame(HEADERS, F_END_HEADERS | es, sid, block);
1873
- return false;
1874
- }
1875
- this._frame(HEADERS, es, sid, block.subarray(0, max));
1876
- let off = max;
1877
- for (;;) {
1878
- const n = Math.min(block.length - off, max);
1879
- const last = off + n >= block.length;
1880
- this._frame(CONTINUATION, last ? F_END_HEADERS : 0,
1881
- sid, block.subarray(off, off + n));
1882
- off += n;
1883
- if (last) {
1884
- return false;
1844
+ // The single-scratch form of every outbound header block: prepare() reads the
1845
+ // caller's map (getters and all) BEFORE any room is reserved, then writePrepared()
1846
+ // writes the HPACK octets straight into this session's staging buffer. No module-level
1847
+ // scratch view, no subarray and no memcpy; the 9-octet frame headers are inserted in
1848
+ // place, from the last CONTINUATION backwards. END_STREAM rides on the first frame
1849
+ // even when CONTINUATIONs follow it (RFC 9113 6.2/5.1/8.1, measured on node's wire).
1850
+ // `prefixSid` adds PUSH_PROMISE's four-octet promised-id prefix; `priority` adds the
1851
+ // allowance node reserves on HEADERS only. `prep` lets a caller that already parsed
1852
+ // (respondWithFD, to keep its error handling around the parse) skip a second pass.
1853
+ // An over-estimate is refused at prep time, not thrown (nghttp2_session.c,
1854
+ // session_prep_frame): node emits 'frameError' and closes a turn later. Measured for
1855
+ // an oversize trailer on v26.12.1: frameError(1, 6, sid), rstCode 6, RST_STREAM(6)
1856
+ // then GOAWAY(0). OPTIMIZATION.md item 68.
1857
+ _writeBlockAt(sid, headers, opts, type, end, prefixSid, priority, prep) {
1858
+ if (prep === undefined) {
1859
+ prep = hdr.prepare(headers, opts, this);
1860
+ }
1861
+ if (prep.bound + (priority ? PRIORITY_SPECLEN : 0) > this._maxSendBlock) {
1862
+ if (type === PUSH_PROMISE) {
1863
+ this._refusePush(sid, prefixSid);
1864
+ } else {
1865
+ this._refuseBlock(sid, type);
1885
1866
  }
1886
- }
1887
- }
1888
-
1889
- // Single-scratch form of sendHeaders: prepare() reads the caller's map (getters and
1890
- // all) BEFORE any room is reserved, then writePrepared() writes HPACK octets straight
1891
- // into this session's staging buffer. There is no module-level scratch view, no
1892
- // subarray and no memcpy for the block; the 9-octet frame headers are inserted into
1893
- // the reserved region in place, from the last CONTINUATION backwards.
1894
- // OPTIMIZATION.md item 68.
1895
- sendHeadersAt(sid, headers, opts, end) {
1896
- const prep = hdr.prepare(headers, opts, this);
1897
- if (prep.bound + PRIORITY_SPECLEN > this._maxSendBlock) {
1898
- this._refuseBlock(sid, HEADERS);
1899
1867
  return true;
1900
1868
  }
1869
+ this.state.deflateDynamicTableSize = this._encoder.size;
1901
1870
  const max = this.remoteSettings.maxFrameSize;
1871
+ const prefix = prefixSid === undefined ? 0 : 4;
1902
1872
  const cap = prep.hit === undefined ? prep.cap : prep.hit.bytes.length;
1903
- const frames = Math.max(1, Math.ceil(cap / max));
1904
- this._need(HEADER_LEN + cap + HEADER_LEN * (frames - 1));
1873
+ const frames = Math.max(1, Math.ceil((prefix + cap) / max));
1874
+ this._need(HEADER_LEN + prefix + cap + HEADER_LEN * (frames - 1));
1905
1875
  const dst = this._stage;
1906
1876
  const off = this._stageLen;
1907
- const payloadOff = off + HEADER_LEN;
1877
+ if (prefix !== 0) {
1878
+ dst.writeUInt32BE(prefixSid, off + HEADER_LEN);
1879
+ }
1880
+ const payloadOff = off + HEADER_LEN + prefix;
1908
1881
  const payloadEnd = hdr.writePrepared(prep, this, dst, payloadOff);
1909
- const n = payloadEnd - payloadOff;
1882
+ const n = payloadEnd - payloadOff + prefix;
1910
1883
  const used = Math.max(1, Math.ceil(n / max));
1911
1884
  if (used === 1) {
1912
- writeHeader(dst, off, n, HEADERS, F_END_HEADERS | (end ? F_END_STREAM : 0), sid);
1885
+ writeHeader(dst, off, n, type, F_END_HEADERS | (end ? F_END_STREAM : 0), sid);
1913
1886
  } else {
1887
+ // The first payload octet is the prefix, not the HPACK block: every later
1888
+ // frame starts max octets after the FIRST frame's payload, which is prefix
1889
+ // octets earlier than payloadOff.
1890
+ const bodyStart = payloadOff - prefix;
1914
1891
  for (let i = used - 1; i >= 1; i--) {
1915
- const src = payloadOff + i * max;
1892
+ const src = bodyStart + i * max;
1916
1893
  const stop = Math.min(payloadEnd, src + max);
1917
1894
  dst.copyWithin(src + i * HEADER_LEN, src, stop);
1918
1895
  }
@@ -1921,7 +1898,7 @@ class Http2ServerSession extends EventEmitter {
1921
1898
  const flags = i === 0 ? (end ? F_END_STREAM : 0)
1922
1899
  : (i === used - 1 ? F_END_HEADERS : 0);
1923
1900
  writeHeader(dst, off + i * (HEADER_LEN + max), take,
1924
- i === 0 ? HEADERS : CONTINUATION, flags, sid);
1901
+ i === 0 ? type : CONTINUATION, flags, sid);
1925
1902
  }
1926
1903
  }
1927
1904
  const total = HEADER_LEN * used + n;
@@ -1933,6 +1910,10 @@ class Http2ServerSession extends EventEmitter {
1933
1910
  return false;
1934
1911
  }
1935
1912
 
1913
+ sendHeadersAt(sid, headers, opts, end) {
1914
+ return this._writeBlockAt(sid, headers, opts, HEADERS, end, undefined, true);
1915
+ }
1916
+
1936
1917
  // node's onFrameError (internal/http2/core.js): the emitter is the stream while the
1937
1918
  // session still holds it and the session otherwise, 'frameError' goes out synchronously,
1938
1919
  // and the close is deferred a turn -- node's own comment says the delay is there to let
@@ -2000,7 +1981,7 @@ class Http2ServerSession extends EventEmitter {
2000
1981
  // with the first frame carrying the 4-octet prefix and the block fragment that fits.
2001
1982
  // Returns true when the block was refused, so pushStream can mark the promised stream
2002
1983
  // before its callback runs (the same contract sendHeaders has with respond()).
2003
- sendPushPromise(parentSid, promisedSid, block, bound) {
1984
+ sendPushPromise(parentSid, promisedSid, headers) {
2004
1985
  // nghttp2's send cycle flushes control frames before DATA, so a PUSH_PROMISE
2005
1986
  // opened in the same turn as the parent's end() rides ahead of the parent's
2006
1987
  // END_STREAM on node's wire. An nghttp2 client refuses a push whose parent is
@@ -2043,47 +2024,19 @@ class Http2ServerSession extends EventEmitter {
2043
2024
  this._esRequeue.push(esBytes !== null ? { bytes: esBytes } : { pair: esPair });
2044
2025
  }
2045
2026
  }
2046
- // The same prep-time estimate sendHeaders refuses on, with no priority spec:
2047
- // session_estimate_headers_payload passes 0 for PUSH_PROMISE. Measured on v26.12.1
2048
- // with a push of {':path':'/pushed', ':authority':'a', 'x-big':'X'.repeat(n)} -- node
2049
- // fills :method and :scheme, so five fields and an estimate of 121+n: under a bound of
2027
+ // The prep-time estimate node uses has no priority allowance on PUSH_PROMISE
2028
+ // (session_estimate_headers_payload passes 0), so _writeBlockAt is called with
2029
+ // priority=false. Measured on v26.12.1 with a push of
2030
+ // {':path':'/pushed', ':authority':'a', 'x-big':'X'.repeat(n)} -- node fills
2031
+ // :method and :scheme, so five fields and an estimate of 121+n: under a bound of
2050
2032
  // 150 n=29 is pushed and n=30 is refused, and under the default n=65415 / 65416
2051
- // (test/outbound-bound.test.js). The refusal lands on the PARENT's
2052
- // 'frameError' (the frame rides on its id) and closes the PROMISED stream with
2053
- // INTERNAL_ERROR, while the parent's own response still goes out and closes it with
2054
- // NO_ERROR -- nghttp2_session_close_stream(promised_sid, NGHTTP2_INTERNAL_ERROR) on
2055
- // the PUSH_PROMISE prep-error path, nghttp2_session.c.
2056
- if (bound > this._maxSendBlock) {
2057
- this._refusePush(parentSid, promisedSid);
2058
- return true;
2059
- }
2060
- this.state.deflateDynamicTableSize = this._encoder.size;
2061
- const max = this.remoteSettings.maxFrameSize;
2062
- // The payload is the 4-byte promised id + the block. The first frame can carry
2063
- // max - 4 bytes of block; the rest goes into CONTINUATION frames.
2064
- const firstCap = max - 4;
2065
- if (block.length <= firstCap) {
2066
- const payload = Buffer.allocUnsafe(4 + block.length);
2067
- payload.writeUInt32BE(promisedSid, 0);
2068
- f.copyInto(payload, 4, block, 0, block.length);
2069
- this._frame(PUSH_PROMISE, F_END_HEADERS, parentSid, payload);
2070
- return false;
2071
- }
2072
- const first = Buffer.allocUnsafe(4 + firstCap);
2073
- first.writeUInt32BE(promisedSid, 0);
2074
- f.copyInto(first, 4, block, 0, firstCap);
2075
- this._frame(PUSH_PROMISE, 0, parentSid, first);
2076
- let off = firstCap;
2077
- for (;;) {
2078
- const n = Math.min(block.length - off, max);
2079
- const last = off + n >= block.length;
2080
- this._frame(CONTINUATION, last ? F_END_HEADERS : 0, parentSid,
2081
- block.subarray(off, off + n));
2082
- off += n;
2083
- if (last) {
2084
- return false;
2085
- }
2086
- }
2033
+ // (test/outbound-bound.test.js). The refusal lands on the PARENT's 'frameError'
2034
+ // and closes the PROMISED stream with INTERNAL_ERROR while the parent's own answer
2035
+ // still goes out: nghttp2_session_close_stream(promised_sid, NGHTTP2_INTERNAL_ERROR).
2036
+ // The promised id is written as the four-octet prefix of the first frame; the rest
2037
+ // of the block is split into CONTINUATIONs by _writeBlockAt.
2038
+ return this._writeBlockAt(parentSid, headers, { request: true },
2039
+ PUSH_PROMISE, false, promisedSid, false);
2087
2040
  }
2088
2041
 
2089
2042
  // Remove a not-yet-committed END_STREAM frame that _frame staged for sid, the
@@ -3908,11 +3861,11 @@ class Http2ServerSession extends EventEmitter {
3908
3861
  // all, the withheld END_STREAM rides on an empty DATA (lib/server/Http2ServerStream.js sendTrailers).
3909
3862
  if (stream._pendingTrailers !== null) {
3910
3863
  const trailers = stream._pendingTrailers;
3911
- const bound = stream._pendingTrailersBound;
3912
3864
  stream._pendingTrailers = null;
3913
3865
  if (trailers.length === 0) {
3914
3866
  this._frame(DATA, F_END_STREAM, stream.id, null);
3915
- } else if (this.sendHeaders(stream.id, trailers, true, bound)) {
3867
+ } else if (this._writeBlockAt(stream.id, trailers, { trailer: true },
3868
+ HEADERS, true, undefined, true)) {
3916
3869
  // The bound is checked when the block is framed, not when sendTrailers() stashed
3917
3870
  // it: nghttp2 compares the estimate at prep time, whenever that happens. Measured
3918
3871
  // on v26.12.1 with a 200 000-octet body ahead of a 64 KiB trailer: frameError
@@ -93,7 +93,7 @@ const { inspect, deprecate } = require('node:util');
93
93
  const frames = require('../frames');
94
94
  const {
95
95
  ST_OPEN, ST_HALF_CLOSED_LOCAL, ST_HALF_CLOSED_REMOTE, ST_CLOSED, NO_ERROR,
96
- PROTOCOL_ERROR, INTERNAL_ERROR
96
+ PROTOCOL_ERROR, INTERNAL_ERROR, HEADERS
97
97
  } = frames;
98
98
  const hdr = require('../headers');
99
99
  const { Http2Stream, EMPTY, READABLE_HWM, emitCloseNT, emitErrorCloseNT, emitErrorOnlyNT, emitEndNT, wantTrailersNT, finishNT, emitEndCloseNT, emitCloseDeliveredNT, autoCloseNT, noopClose, FILE_CHUNK, isFileHandle, argTypeError, fdOptions, prepareResponseHeadersObject, errorOf, validateRstCode, abortError, validateObjectArg, validateSignalArg, streamErrorOf, createStreamIterator } = require('../Http2Stream');
@@ -174,8 +174,7 @@ class Http2ServerStream extends Http2Stream {
174
174
  // batch, so sendTrailers() closes the stream without staging a second one, and
175
175
  // addTrailers() after end() recalls the frame instead
176
176
  this._esStaged = false;
177
- this._pendingTrailers = null; // trailer block waiting behind a queued body
178
- this._pendingTrailersBound = 0; // ...and its outbound estimate, checked when it drains
177
+ this._pendingTrailers = null; // trailer map waiting behind a queued body
179
178
  // A refused outbound HEADERS (session._refuseBlock) left the wire a step behind the
180
179
  // application: no response HEADERS means no DATA may follow, and no END_STREAM means
181
180
  // the stream must not close gracefully. An informational block sets neither.
@@ -560,9 +559,11 @@ class Http2ServerStream extends Http2Stream {
560
559
  this.headersSent = true;
561
560
  this.pending = false;
562
561
  this._ending = true;
563
- let block;
562
+ let prep;
564
563
  try {
565
- block = hdr.block(prepared, { sendDate }, this.session);
564
+ // prepare() reads the map here, inside the descriptor's error handling, and
565
+ // _writeBlockAt writes the octets straight into the session's staging buffer.
566
+ prep = hdr.prepare(prepared, { sendDate }, this.session);
566
567
  } catch (err) {
567
568
  if (this.ownsFd) {
568
569
  fs.close(fd, noopClose);
@@ -573,8 +574,9 @@ class Http2ServerStream extends Http2Stream {
573
574
  this._sentSrc = prepared;
574
575
  this._sentStatus = hdr.sent.status;
575
576
  this._sentDate = hdr.sent.date;
576
- const bound = hdr.sent.bound;
577
- if (this._blockRefused || this.session.sendHeaders(this.id, block, false, bound)) {
577
+ if (this._blockRefused ||
578
+ this.session._writeBlockAt(this.id, prepared, { sendDate }, HEADERS,
579
+ false, undefined, true, prep)) {
578
580
  this._blockRefused = true;
579
581
  // node has already called self.end() by this point (processRespondWithFD ends
580
582
  // the writable before the wire write), so the half-close happens even here.
@@ -794,16 +796,12 @@ class Http2ServerStream extends Http2Stream {
794
796
  throw errorOf('ERR_HTTP2_TRAILERS_NOT_READY',
795
797
  'Trailing headers cannot be sent until after the wantTrailers event is emitted');
796
798
  }
797
- let block;
798
- let bound;
799
- // An empty trailer map is skipped, not run through block(): nothing in it can fail
800
- // validation (no name to check, no single-value rule to trip) and it encodes to zero
801
- // octets, while block() allocates the parse key list, the strict-singles scratch and
802
- // the parse result for every one of them -- and every compat response ends with an
803
- // empty trailer map, because the (req,res) layer always answers 'wantTrailers' with
804
- // what it recorded: nothing at all when the application added none (item 44).
805
- // hdr.sent must not be read for the skipped case: it still holds the previous
806
- // block's result.
799
+ // An empty trailer map is skipped, not run through the encoder: nothing in it can
800
+ // fail validation (no name to check, no single-value rule to trip) and it encodes to
801
+ // zero octets, while prepare() still allocates the parse key list, the
802
+ // strict-singles scratch and the parse result -- and every compat response ends with
803
+ // an empty trailer map, because the (req,res) layer always answers 'wantTrailers'
804
+ // with what it recorded: nothing at all when the application added none (item 44).
807
805
  let empty = true;
808
806
  for (const key in trailers) {
809
807
  if (Object.prototype.hasOwnProperty.call(trailers, key)) {
@@ -811,23 +809,12 @@ class Http2ServerStream extends Http2Stream {
811
809
  break;
812
810
  }
813
811
  }
814
- if (empty) {
815
- block = EMPTY;
816
- bound = 0;
817
- } else {
818
- block = hdr.block(trailers, { trailer: true }, this.session);
819
- bound = hdr.sent.bound;
820
- // Own these octets before the copy below reads the caller's getters. A getter
821
- // can call block() for another response, and block() returns a view into the
822
- // module-level scratch shared by every session: the bytes would be rewritten
823
- // before sendHeaders() stages this frame (reproduced with a reentrant getter
824
- // in the trailers object -- the peer saw COMPRESSION_ERROR instead of them).
825
- // The queued path below uses this copy too, so it still copies only once.
826
- block = Buffer.from(block);
827
- }
828
812
  // node records a null-prototype copy, not the caller's map (`ObjectAssign({
829
813
  // __proto__: null }, headers)`, internal/http2/core.js sendTrailers -- the shared
830
- // base method, so the client stream records the same shape).
814
+ // base method, so the client stream records the same shape). Reading the getters
815
+ // here once also fixes the values for a body that is still queued: the block is
816
+ // encoded when that body drains, and prepare()/writePrepared() write straight into
817
+ // the session's stage from parsed values, so a reentrant getter cannot rewrite it.
831
818
  this.sentTrailers = Object.assign({ __proto__: null }, trailers);
832
819
  // the trailers are out: the flag that permitted this call must not keep asking for
833
820
  // wantTrailers, whatever happens to the bytes below
@@ -848,15 +835,12 @@ class Http2ServerStream extends Http2Stream {
848
835
  // because node's (req,res) layer always asks for trailers (internal/http2/compat.js
849
836
  // kBeginSend passes waitForTrailers: true) and answers with the empty trailer map
850
837
  // when the application added none.
851
- empty = block.length === 0;
852
838
  if (this._queued !== null) {
853
839
  // The body is still waiting for credit or for the socket, and this block has to
854
840
  // follow it: END_STREAM rides on the trailers, so a HEADERS sent now would outrun
855
- // DATA that has not gone out. The block was already made owned above (the
856
- // zero-length marker needs none); let the session put it on the wire when the
857
- // queue drains.
858
- this._pendingTrailers = empty ? EMPTY : block;
859
- this._pendingTrailersBound = bound;
841
+ // DATA that has not gone out. Stash the fixed copy; the session encodes it when
842
+ // the queue drains. A zero-length stash is the empty-map marker above.
843
+ this._pendingTrailers = empty ? EMPTY : this.sentTrailers;
860
844
  return this;
861
845
  }
862
846
  if (empty) {
@@ -864,7 +848,7 @@ class Http2ServerStream extends Http2Stream {
864
848
  this.session.sendData(this, EMPTY, true);
865
849
  return this;
866
850
  }
867
- if (this.session.sendHeaders(this.id, block, true, bound)) {
851
+ if (this.session.sendHeadersAt(this.id, this.sentTrailers, { trailer: true }, true)) {
868
852
  // The END_STREAM this block carried never went out, so the stream has not finished
869
853
  // on the wire and must not close on its own terms ahead of the deferred
870
854
  // FRAME_SIZE_ERROR close (session._refuseBlock).
@@ -926,12 +910,10 @@ class Http2ServerStream extends Http2Stream {
926
910
  }
927
911
  // `{ info: true }` is node's separate rule for these blocks: :status must be 100..199
928
912
  // (101 has its own error), there is no default status and no generated date.
929
- const block = hdr.block(headers, { info: true }, this.session);
930
- const bound = hdr.sent.bound;
931
- // Own the bytes before Object.assign reads the caller's getters: one of them
932
- // can build another block and overwrite the shared scratch this view points
933
- // into (the trailers path above has the same window).
934
- const owned = Buffer.from(block);
913
+ // prepare() performs that validation before the copy is made, and the plan it
914
+ // returns lets _writeBlockAt write the octets straight into the session's stage
915
+ // without a scratch view or a second walk over getters.
916
+ const prep = hdr.prepare(headers, { info: true }, this.session);
935
917
  // node stores a null-proto copy of each informational block, created at the
936
918
  // first call (internal/http2/core.js:3265, 3285) -- the caller's object is
937
919
  // not retained, and the array does not exist before the first call.
@@ -941,7 +923,8 @@ class Http2ServerStream extends Http2Stream {
941
923
  } else {
942
924
  this.sentInfoHeaders.push(copy);
943
925
  }
944
- this.session.sendHeaders(this.id, owned, false, bound);
926
+ this.session._writeBlockAt(this.id, copy, { info: true }, HEADERS, false,
927
+ undefined, true, prep);
945
928
  return this;
946
929
  }
947
930
 
@@ -1057,8 +1040,9 @@ class Http2ServerStream extends Http2Stream {
1057
1040
  // the frame is submitted). The id was already reserved; it stays consumed.
1058
1041
  // Like respond(), the never-indexed names come only off the headers object's
1059
1042
  // sensitiveHeaders symbol -- node's pushStream has no options.sensitiveHeaders.
1060
- const block = hdr.pushBlock(h, this.session);
1061
- const refused = this.session.sendPushPromise(this.id, promisedId, block, hdr.sent.bound);
1043
+ // sendPushPromise prepares the request-shaped block itself and writes its
1044
+ // promised-id prefix plus the HPACK octets straight into the session's stage.
1045
+ const refused = this.session.sendPushPromise(this.id, promisedId, h);
1062
1046
 
1063
1047
  // Create the pushed stream and register it. The readable side is pre-ended:
1064
1048
  // remoteClose=1 means _endLocalSide() takes the graceful close path (no RST),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h2lean",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Pure-JavaScript HTTP/2 for Node.js — a drop-in node:http2 replacement (server and client, h2c and TLS) with zero dependencies",
5
5
  "main": "index.js",
6
6
  "files": [