h2lean 0.2.3 → 0.2.4
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/client-session.js +5 -3
- package/lib/headers.js +31 -6
- package/lib/session.js +36 -2
- package/package.json +1 -1
package/lib/client-session.js
CHANGED
|
@@ -519,8 +519,9 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
519
519
|
if (this._strictSingle) {
|
|
520
520
|
// the duplicate check rides _addField's own loop, the way node's
|
|
521
521
|
// processHeader runs it inside buildNgHeaderString's one pass; the scratch
|
|
522
|
-
//
|
|
523
|
-
|
|
522
|
+
// is dropped here -- reassigned, not length-cleared, for the same
|
|
523
|
+
// right-trim reason as the module scratch in headers.js (OPTIMIZATION.md item 38)
|
|
524
|
+
this._singlesSeen = [];
|
|
524
525
|
}
|
|
525
526
|
if (Array.isArray(src)) {
|
|
526
527
|
for (let i = 0; i + 1 < src.length; i += 2) {
|
|
@@ -1855,7 +1856,8 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
1855
1856
|
r.stream.destroy(cancelErr(err));
|
|
1856
1857
|
}
|
|
1857
1858
|
}
|
|
1858
|
-
|
|
1859
|
+
// reassigned, not length-cleared (OPTIMIZATION.md item 38)
|
|
1860
|
+
this._outboundQueue = [];
|
|
1859
1861
|
const socket = this.socket;
|
|
1860
1862
|
this._discardOut();
|
|
1861
1863
|
if (!socket.destroyed) {
|
package/lib/headers.js
CHANGED
|
@@ -195,6 +195,22 @@ function nameCacheSize() {
|
|
|
195
195
|
// node does not make.
|
|
196
196
|
const badValue = /[\u0000-\u0008\u000a-\u001f\u007f]/;
|
|
197
197
|
|
|
198
|
+
// The strict-single-value scratch for parse(): one array for the whole module,
|
|
199
|
+
// cleared at entry and never held across a call -- parse() is synchronous and
|
|
200
|
+
// runs no callback, so no call can observe another's list. The shape is node's
|
|
201
|
+
// own (buildNgHeaderString checks a lazily-grown array inline in its one pass,
|
|
202
|
+
// internal/http2/util.js) and the one the client's request() carries
|
|
203
|
+
// (lib/client-session.js, OPTIMIZATION.md item 36). Measured honestly: at the
|
|
204
|
+
// granularity parse() acts on, the swap from a per-call Set is inside the noise
|
|
205
|
+
// -- item 36's win came from removing request()'s second pass over the flat
|
|
206
|
+
// list, which parse() never had; the component costs are in OPTIMIZATION.md
|
|
207
|
+
// item 37. It is kept for the shape parity, not for speed
|
|
208
|
+
// (bench/micro/parse-singles.js).
|
|
209
|
+
// Reassigned, not length-cleared: `length = 0` right-trims the backing store so the
|
|
210
|
+
// next fill re-grows it, and the fresh allocation measures cheaper on both time and,
|
|
211
|
+
// at the sizes this sees, GC (OPTIMIZATION.md item 38).
|
|
212
|
+
let singlesSeen = [];
|
|
213
|
+
|
|
198
214
|
// Kept as a Set: at five names the shape of the operation decides it, not the
|
|
199
215
|
// size (OPTIMIZATION.md item 10).
|
|
200
216
|
// RFC 9113 8.2.2 forbids these on an HTTP/2 connection: they are hop-by-hop in HTTP/1.1,
|
|
@@ -271,9 +287,16 @@ function parse(headers, sensitive,
|
|
|
271
287
|
throw httpError('ERR_HTTP2_INVALID_HEADER_VALUE', 'headers must be an object');
|
|
272
288
|
}
|
|
273
289
|
const neverSet = sensitive || headers[KSensitiveHeaders];
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
290
|
+
// Inserted in one loop, not new Set(neverSet.map(...)): the map's intermediate array
|
|
291
|
+
// and its closure are one allocation each per sensitive response, measured at
|
|
292
|
+
// bench/micro/parse-singles.js.
|
|
293
|
+
let neverList = null;
|
|
294
|
+
if (Array.isArray(neverSet) && neverSet.length > 0) {
|
|
295
|
+
neverList = new Set();
|
|
296
|
+
for (let i = 0; i < neverSet.length; i++) {
|
|
297
|
+
neverList.add(lowerName(neverSet[i]));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
277
300
|
|
|
278
301
|
const pseudo = [];
|
|
279
302
|
const fields = [];
|
|
@@ -294,7 +317,9 @@ function parse(headers, sensitive,
|
|
|
294
317
|
// copy -- regular field or pseudo-header alike -- or for a multi-element array on
|
|
295
318
|
// one, before any stream or octet exists. The singles walk stays in field order, so
|
|
296
319
|
// the first problem in the caller's order is the one reported.
|
|
297
|
-
|
|
320
|
+
if (strict) {
|
|
321
|
+
singlesSeen = [];
|
|
322
|
+
}
|
|
298
323
|
for (let i = 0; i < keys.length; i++) {
|
|
299
324
|
let key;
|
|
300
325
|
let raw;
|
|
@@ -325,11 +350,11 @@ function parse(headers, sensitive,
|
|
|
325
350
|
throw httpError('ERR_HTTP2_HEADER_SINGLE_VALUE',
|
|
326
351
|
`Header field "${key}" must only have a single value`);
|
|
327
352
|
}
|
|
328
|
-
if (
|
|
353
|
+
if (singlesSeen.indexOf(key) !== -1) {
|
|
329
354
|
throw httpError('ERR_HTTP2_HEADER_SINGLE_VALUE',
|
|
330
355
|
`Header field "${key}" must only have a single value`);
|
|
331
356
|
}
|
|
332
|
-
|
|
357
|
+
singlesSeen.push(key);
|
|
333
358
|
}
|
|
334
359
|
|
|
335
360
|
if (key[0] === ':') {
|
package/lib/session.js
CHANGED
|
@@ -469,6 +469,23 @@ class Http2Session extends EventEmitter {
|
|
|
469
469
|
this._rstSec = (Date.now() / 1000) | 0;
|
|
470
470
|
|
|
471
471
|
this._maxInboundSid = 0;
|
|
472
|
+
// The highest id of a HEADERS frame this side has accepted -- nghttp2 opens the
|
|
473
|
+
// stream in prep_frame, after the length, padding and priority checks but BEFORE
|
|
474
|
+
// the block is decoded or any verdict on it is given, and its last-proc-stream-id
|
|
475
|
+
// (which node reports as state.lastProcStreamID and puts in GOAWAY's last-stream
|
|
476
|
+
// id) moves there. A GOAWAY sent for a frame refused after that point therefore
|
|
477
|
+
// names the stream of the refused frame, measured on v26.12.1 for an undecodable
|
|
478
|
+
// block and a header list over maxHeaderListSize (last=1 against h2lean's 0,
|
|
479
|
+
// out/probe-last-id.js) -- the shape a client reads as its retry boundary, so a
|
|
480
|
+
// lower id makes it resend a request that was already acted on. Control frames
|
|
481
|
+
// never move it -- measured on the same probe: WINDOW_UPDATE, RST_STREAM and DATA
|
|
482
|
+
// refused above the line all answer last=1, the served stream, on BOTH stacks --
|
|
483
|
+
// and frames refused before the acceptance point (over max frame size, malformed
|
|
484
|
+
// padding or priority, an even id) do not either: nghttp2 fails them before the
|
|
485
|
+
// open. Only _fatal reads it; the idle-state rules below stay keyed on
|
|
486
|
+
// _maxInboundSid, whose raise waits for the skip-record check (5.1.1) that must
|
|
487
|
+
// see the line as it was when the frame arrived.
|
|
488
|
+
this._reachedSid = 0;
|
|
472
489
|
this._refused = [];
|
|
473
490
|
this._dropped = null; // ids a reset ended, newest last
|
|
474
491
|
// ids whose message ended in the read batch being processed, see _dropStream. Cleared by the
|
|
@@ -823,7 +840,9 @@ class Http2Session extends EventEmitter {
|
|
|
823
840
|
const n = chunk.length;
|
|
824
841
|
let i = 0;
|
|
825
842
|
this._inBatch = true;
|
|
826
|
-
|
|
843
|
+
// dropped, not length-cleared -- reassignment measures cheaper than the
|
|
844
|
+
// right-trim the length store does (OPTIMIZATION.md item 38)
|
|
845
|
+
this._ended = []; // the last batch's finished streams are no longer here
|
|
827
846
|
this._touchIdleTimer();
|
|
828
847
|
|
|
829
848
|
if (this._prefaceSeen < PREFACE_LEN) {
|
|
@@ -1297,6 +1316,11 @@ class Http2Session extends EventEmitter {
|
|
|
1297
1316
|
return;
|
|
1298
1317
|
}
|
|
1299
1318
|
const l = this._hdrFrag;
|
|
1319
|
+
// the frame is accepted: nghttp2 opens its stream here, before the block is
|
|
1320
|
+
// decoded -- see _reachedSid
|
|
1321
|
+
if (sid > this._reachedSid) {
|
|
1322
|
+
this._reachedSid = sid;
|
|
1323
|
+
}
|
|
1300
1324
|
if (flags & F_END_HEADERS) {
|
|
1301
1325
|
this._processHeaders(sid, (flags & F_END_STREAM) !== 0, buf.subarray(start + p, start + p + l));
|
|
1302
1326
|
return;
|
|
@@ -1324,6 +1348,11 @@ class Http2Session extends EventEmitter {
|
|
|
1324
1348
|
return;
|
|
1325
1349
|
}
|
|
1326
1350
|
const l = this._hdrFrag;
|
|
1351
|
+
// the frame is accepted: nghttp2 opens its stream here, before the block is
|
|
1352
|
+
// decoded -- see _reachedSid
|
|
1353
|
+
if (sid > this._reachedSid) {
|
|
1354
|
+
this._reachedSid = sid;
|
|
1355
|
+
}
|
|
1327
1356
|
if (flags & F_END_HEADERS) {
|
|
1328
1357
|
this._processBlockPieces(sid, (flags & F_END_STREAM) !== 0, pieces, p, p + l);
|
|
1329
1358
|
return;
|
|
@@ -2396,7 +2425,12 @@ class Http2Session extends EventEmitter {
|
|
|
2396
2425
|
if (!this._open) {
|
|
2397
2426
|
return;
|
|
2398
2427
|
}
|
|
2399
|
-
|
|
2428
|
+
// last-stream id names the far side of the retry boundary: a stream whose HEADERS
|
|
2429
|
+
// was accepted but whose block was refused was reached, and node names it (see
|
|
2430
|
+
// _reachedSid) -- naming only the streams a stream object was made for would tell
|
|
2431
|
+
// the peer it may retry a request that was already acted on
|
|
2432
|
+
const reached = this._maxInboundSid > this._reachedSid ? this._maxInboundSid : this._reachedSid;
|
|
2433
|
+
this.sendGoaway(reached, code, msg);
|
|
2400
2434
|
this._flush();
|
|
2401
2435
|
const err = errorOf('ERR_HTTP2_SESSION_ERROR', msg);
|
|
2402
2436
|
err.http2Code = code;
|
package/package.json
CHANGED