h2lean 0.8.1 → 0.10.0

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.
@@ -103,13 +103,12 @@
103
103
  // reaches the wire, and a destroyed session reports closed false. Measured on a live
104
104
  // node client for all three calls.
105
105
  //
106
- // KNOWN DIVERGENCE: an inbound NO_ERROR GOAWAY whose lastStreamID is below the open ids
107
- // makes node refuse the unprocessed streams itself -- rstCode 7, ERR_HTTP2_STREAM_ERROR
108
- // naming NGHTTP2_REFUSED_STREAM, and the session destroys once they are gone. Here they
109
- // are not refused at all: rstCode stays 0, the streams stay open and the session stays
110
- // closed-but-not-destroyed until the connection goes. Measured with two open requests
111
- // and lastStreamID 0; the same shape with lastStreamID above them agrees on both arms
112
- // and is pinned by test/client/client-goaway-inbound.test.js.
106
+ // A NO_ERROR GOAWAY whose lastStreamID is below the open ids refuses the retired streams
107
+ // here, as node does: every locally-initiated (odd) stream above lastStreamID closes with
108
+ // NGHTTP2_REFUSED_STREAM -- rstCode 7, ERR_HTTP2_STREAM_ERROR naming it, no session-level
109
+ // error -- and the graceful close completes once they are gone. A mark above the open ids
110
+ // refuses nothing. Measured with two unanswered requests and lastStreamID 0 and 5 against
111
+ // a raw peer; both shapes pinned by test/client/client-goaway-inbound.test.js.
113
112
  'use strict';
114
113
 
115
114
  const { EventEmitter } = require('node:events');
@@ -141,7 +140,7 @@ const {
141
140
  DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS, PUSH_PROMISE, PING, GOAWAY,
142
141
  WINDOW_UPDATE, CONTINUATION, ALTSVC, ORIGIN,
143
142
  F_END_STREAM, F_ACK, F_END_HEADERS, F_PADDED, F_PRIORITY,
144
- NO_ERROR, PROTOCOL_ERROR, INTERNAL_ERROR, FRAME_SIZE_ERROR, COMPRESSION_ERROR, CANCEL, REFUSED_STREAM,
143
+ NO_ERROR, PROTOCOL_ERROR, INTERNAL_ERROR, FLOW_CONTROL_ERROR, FRAME_SIZE_ERROR, COMPRESSION_ERROR, CANCEL, REFUSED_STREAM,
145
144
  HEADER_LEN, PREFACE, PREFACE_LEN, readHeader, writeHeader, trimPadding
146
145
  } = f;
147
146
 
@@ -786,6 +785,20 @@ class ClientHttp2Session extends EventEmitter {
786
785
  let sawMethod = false;
787
786
 
788
787
  const src = headersParam === undefined ? {} : headersParam;
788
+ // node reads the never-indexed names off the headers param's sensitiveHeaders
789
+ // symbol in both shapes -- array or object (buildNgHeaderString reads
790
+ // arrayOrMap[kSensitiveHeaders], internal/http2/util.js) -- lowercases them,
791
+ // and flags every field line whose name is in the list as a never-indexed
792
+ // literal. The wire half is pinned by the server-side receive in
793
+ // test/upstream/sensitive-headers.test.js, the object half by sentHeaders.
794
+ const sensitive = src[KSensitiveHeaders];
795
+ let neverList = null;
796
+ if (Array.isArray(sensitive) && sensitive.length > 0) {
797
+ neverList = new Set();
798
+ for (let i = 0; i < sensitive.length; i++) {
799
+ neverList.add(lowerName(sensitive[i]));
800
+ }
801
+ }
789
802
  if (this._strictSingle) {
790
803
  // the duplicate check rides _addField's own loop, the way node's
791
804
  // processHeader runs it inside buildNgHeaderString's one pass; the scratch
@@ -795,23 +808,26 @@ class ClientHttp2Session extends EventEmitter {
795
808
  }
796
809
  if (Array.isArray(src)) {
797
810
  for (let i = 0; i + 1 < src.length; i += 2) {
798
- this._addField(list, src[i], src[i + 1]);
811
+ this._addField(list, neverList, src[i], src[i + 1]);
799
812
  }
800
813
  } else {
801
814
  const keys = Object.keys(src);
802
815
  for (let i = 0; i < keys.length; i++) {
803
- this._addField(list, keys[i], src[keys[i]]);
816
+ this._addField(list, neverList, keys[i], src[keys[i]]);
804
817
  }
805
818
  }
806
819
  // list may already contain app pseudo-headers; extract method for the endStream
807
820
  // default and the pseudo-header completion node performs.
808
- for (let i = 0; i < list.length; i += 2) {
821
+ for (let i = 0; i < list.length; i += 3) {
809
822
  if (list[i] === ':method') {
810
823
  method = list[i + 1]; sawMethod = true; break;
811
824
  }
812
825
  }
813
826
  if (!sawMethod) {
814
- list.push(':method', method);
827
+ // node fills the pseudo-header into the map before the flags are computed,
828
+ // so a name the application marked reaches the fill too (processHeader
829
+ // applies neverIndex.includes(key) to pseudo lines as well).
830
+ list.push(':method', method, neverList !== null && neverList.has(':method'));
815
831
  }
816
832
 
817
833
  let endStream = options === undefined ? undefined : options.endStream;
@@ -835,7 +851,7 @@ class ClientHttp2Session extends EventEmitter {
835
851
  // headers are only filled into the outbound list later, in _sendRequest, so the
836
852
  // same resolution is done here against the list as it stands.
837
853
  let originScheme, originAuthority;
838
- for (let i = 0; i < list.length; i += 2) {
854
+ for (let i = 0; i < list.length; i += 3) {
839
855
  const key = list[i];
840
856
  if (key === ':scheme') {
841
857
  if (originScheme === undefined) {
@@ -895,7 +911,7 @@ class ClientHttp2Session extends EventEmitter {
895
911
  // object across requests, the HPACK encoder produces identical bytes every time
896
912
  // after the dynamic table stabilises, and _sendRequest can use _blocks to replay
897
913
  // the encoded block without re-encoding. (The server's shareHeaders equivalent.)
898
- const req = { stream, list, end: endStream, hp: headersParam };
914
+ const req = { stream, list, nl: neverList, end: endStream, hp: headersParam };
899
915
  if (requestError !== undefined) {
900
916
  // node's requestOnError: destroy the stream with the captured error on the
901
917
  // next tick, and submit nothing. The id reserved above is never used -- the
@@ -946,7 +962,7 @@ class ClientHttp2Session extends EventEmitter {
946
962
  // the peer's number and not the 65535 default the peer may never have chosen.
947
963
  req.stream._sendWin = this.remoteSettings.initialWindowSize;
948
964
  this._streams.set(req.stream.id, req.stream);
949
- this._sendRequest(req.stream, req.list, req.end, req.hp);
965
+ this._sendRequest(req.stream, req.list, req.nl, req.end, req.hp);
950
966
  }
951
967
 
952
968
  // A slot just freed (a stream closed): start queued requests while the peer's
@@ -968,10 +984,14 @@ class ClientHttp2Session extends EventEmitter {
968
984
  }
969
985
  }
970
986
 
971
- // Normalises one application-supplied field into the flat [name, value, ...] list:
972
- // lower-cases names, coerces pseudo/regular, rejects connection-specific fields
973
- // (RFC 9113 8.2.2) and a non-token name (RFC 9113 8.2.1) exactly as node's
974
- // prepareRequestHeaders* does for a client request.
987
+ // Normalises one application-supplied field into the flat [name, value, never, ...]
988
+ // list: lower-cases names, coerces pseudo/regular, rejects connection-specific
989
+ // fields (RFC 9113 8.2.2) and a non-token name (RFC 9113 8.2.1) exactly as node's
990
+ // prepareRequestHeaders* does for a client request. The third slot carries the
991
+ // never-indexed flag the encoder writes into the literal form (0x10): node flags
992
+ // each line whose lower-cased name is in the headers param's sensitiveHeaders
993
+ // list (buildNgHeaderString, internal/http2/util.js), and `neverList` is that
994
+ // list as a Set, or null when the application marked nothing.
975
995
  //
976
996
  // The strict single-value rule rides this same loop, the way node's processHeader
977
997
  // runs it inside buildNgHeaderString's one pass (internal/http2/util.js): a
@@ -981,11 +1001,12 @@ class ClientHttp2Session extends EventEmitter {
981
1001
  // at, which is why the check stands above the pseudo branch; an empty array is
982
1002
  // skipped before any bookkeeping (node's `case 0: return`), so it neither pushes
983
1003
  // a value nor spends a slot in _singlesSeen.
984
- _addField(list, rawKey, rawValue) {
1004
+ _addField(list, neverList, rawKey, rawValue) {
985
1005
  if (rawValue === undefined) {
986
1006
  return;
987
1007
  }
988
1008
  const key = lowerName(rawKey);
1009
+ const never = neverList !== null && neverList.has(key);
989
1010
  const isArray = Array.isArray(rawValue);
990
1011
  if (isArray && rawValue.length === 0) {
991
1012
  return;
@@ -1011,7 +1032,7 @@ class ClientHttp2Session extends EventEmitter {
1011
1032
  && key !== ':protocol') {
1012
1033
  throw httpErr('ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED', `cannot send ${key}`);
1013
1034
  }
1014
- list.push(key, String(isArray ? rawValue[0] : rawValue));
1035
+ list.push(key, String(isArray ? rawValue[0] : rawValue), never);
1015
1036
  return;
1016
1037
  }
1017
1038
  if (!isFieldName(key)) {
@@ -1023,17 +1044,20 @@ class ClientHttp2Session extends EventEmitter {
1023
1044
  }
1024
1045
  if (isArray) {
1025
1046
  for (let j = 0; j < rawValue.length; j++) {
1026
- list.push(key, String(rawValue[j]));
1047
+ list.push(key, String(rawValue[j]), never);
1027
1048
  }
1028
1049
  } else {
1029
- list.push(key, String(rawValue));
1050
+ list.push(key, String(rawValue), never);
1030
1051
  }
1031
1052
  }
1032
1053
 
1033
- _sendRequest(stream, list, end, hp) {
1054
+ _sendRequest(stream, list, neverList, end, hp) {
1034
1055
  // Fill the pseudo-headers the application omitted, in the canonical order, then
1035
1056
  // hand the whole list to HPACK. node completes :path to '/', :scheme and
1036
1057
  // :authority from the session; we mirror that so `request({})` is a GET /.
1058
+ // The fills carry the never-indexed flag the way node's does: the names land
1059
+ // in the map before buildNgHeaderString computes the flags, so an application
1060
+ // that marked ':path' marks the fill with it.
1037
1061
  //
1038
1062
  // The outbound block cache: when the same headersParam object is passed to
1039
1063
  // request() again and the encoder's dynamic-table epoch has not moved since
@@ -1054,13 +1078,14 @@ class ClientHttp2Session extends EventEmitter {
1054
1078
  bound = cached.bound;
1055
1079
  } else {
1056
1080
  if (!list.includes(':path')) {
1057
- list.push(':path', '/');
1081
+ list.push(':path', '/', neverList !== null && neverList.has(':path'));
1058
1082
  }
1059
1083
  if (!list.includes(':scheme')) {
1060
- list.push(':scheme', this._scheme);
1084
+ list.push(':scheme', this._scheme, neverList !== null && neverList.has(':scheme'));
1061
1085
  }
1062
1086
  if (!list.includes(':authority')) {
1063
- list.push(':authority', this._authority);
1087
+ list.push(':authority', this._authority,
1088
+ neverList !== null && neverList.has(':authority'));
1064
1089
  }
1065
1090
  const ordered = orderPseudo(list);
1066
1091
  block = this._encodeRequest(ordered);
@@ -1101,7 +1126,7 @@ class ClientHttp2Session extends EventEmitter {
1101
1126
  // alongside the buffer: the block cache below has to carry it too, and a second
1102
1127
  // return value would mean an object per request.
1103
1128
  let bound = 12;
1104
- for (let i = 0; i < list.length; i += 2) {
1129
+ for (let i = 0; i < list.length; i += 3) {
1105
1130
  cap += Encoder.maxBytesOf(list[i], list[i + 1]);
1106
1131
  bound += 12 + list[i].length + list[i + 1].length;
1107
1132
  }
@@ -1119,8 +1144,8 @@ class ClientHttp2Session extends EventEmitter {
1119
1144
  const buf = Buffer.allocUnsafe(ul + cap);
1120
1145
  enc.unsettled = false;
1121
1146
  let off = ul;
1122
- for (let i = 0; i < list.length; i += 2) {
1123
- off = enc.write(buf, off, list[i], list[i + 1], false);
1147
+ for (let i = 0; i < list.length; i += 3) {
1148
+ off = enc.write(buf, off, list[i], list[i + 1], list[i + 2]);
1124
1149
  }
1125
1150
  if (ul === 0) {
1126
1151
  return buf.subarray(0, off);
@@ -1302,14 +1327,24 @@ class ClientHttp2Session extends EventEmitter {
1302
1327
  const list = [];
1303
1328
  this._singlesSeen = [];
1304
1329
  const src = trailers === undefined || trailers === null ? {} : trailers;
1330
+ // The never-indexed mark rides the trailers param's sensitiveHeaders symbol the
1331
+ // same way it does on a request (buildNgHeaderString reads it in both shapes).
1332
+ const sensitive = src[KSensitiveHeaders];
1333
+ let neverList = null;
1334
+ if (Array.isArray(sensitive) && sensitive.length > 0) {
1335
+ neverList = new Set();
1336
+ for (let i = 0; i < sensitive.length; i++) {
1337
+ neverList.add(lowerName(sensitive[i]));
1338
+ }
1339
+ }
1305
1340
  if (Array.isArray(src)) {
1306
1341
  for (let i = 0; i + 1 < src.length; i += 2) {
1307
- this._addField(list, src[i], src[i + 1]);
1342
+ this._addField(list, neverList, src[i], src[i + 1]);
1308
1343
  }
1309
1344
  } else {
1310
1345
  const keys = Object.keys(src);
1311
1346
  for (let i = 0; i < keys.length; i++) {
1312
- this._addField(list, keys[i], src[keys[i]]);
1347
+ this._addField(list, neverList, keys[i], src[keys[i]]);
1313
1348
  }
1314
1349
  }
1315
1350
  // RFC 9113 8.1: a trailer block carries no pseudo-header. _addField throws
@@ -2371,7 +2406,17 @@ class ClientHttp2Session extends EventEmitter {
2371
2406
  if (inc === 0) {
2372
2407
  this._fatal(PROTOCOL_ERROR, 'WINDOW_UPDATE increment of 0'); return;
2373
2408
  }
2409
+ // RFC 9113 6.9.1: a WINDOW_UPDATE that would push a send window past 2^31-1 is a
2410
+ // connection error, not a stream error -- nghttp2 ends the whole session for both
2411
+ // the per-stream and the per-connection window (measured on a live node v26.12.1
2412
+ // client: GOAWAY(FLOW_CONTROL_ERROR) outbound, ERR_HTTP2_ERROR on the stream and
2413
+ // the session, the stream closed with rstCode NGHTTP2_INTERNAL_ERROR). Without the
2414
+ // cap the client's window simply absorbs every increment, an unbounded number a
2415
+ // peer controls.
2374
2416
  if (sid === 0) {
2417
+ if (this._connSendWin + inc > 0x7fffffff) {
2418
+ this._fatal(FLOW_CONTROL_ERROR, 'connection window overflow'); return;
2419
+ }
2375
2420
  this._connSendWin += inc;
2376
2421
  for (const s of this._streams.values()) {
2377
2422
  this._pump(s);
@@ -2382,6 +2427,9 @@ class ClientHttp2Session extends EventEmitter {
2382
2427
  if (stream === undefined) {
2383
2428
  return;
2384
2429
  }
2430
+ if (stream._sendWin + inc > 0x7fffffff) {
2431
+ this._fatal(FLOW_CONTROL_ERROR, 'stream window overflow'); return;
2432
+ }
2385
2433
  stream._sendWin += inc;
2386
2434
  this._pump(stream);
2387
2435
  }
@@ -2440,7 +2488,33 @@ class ClientHttp2Session extends EventEmitter {
2440
2488
  // 0, 1, 3 and 5: the session and every open stream error and close in that order,
2441
2489
  // destroyed true and closed false, GOAWAY(0,0) alone on the wire with no RST_STREAM.
2442
2490
  // Pinned by test/client/client-goaway-inbound.test.js.
2491
+ //
2492
+ // nghttp2 refuses the streams the GOAWAY retires itself: every locally-initiated
2493
+ // stream above lastStreamID closes with NGHTTP2_REFUSED_STREAM (measured on a live
2494
+ // node v26.12.1 client with two unanswered requests and lastStreamID 0: the stream
2495
+ // errors and closes NEWEST id first -- req on id 3 before the one on id 1, the
2496
+ // reverse of the non-zero destroy's ascending order -- each with ERR_HTTP2_STREAM_ERROR
2497
+ // naming NGHTTP2_REFUSED_STREAM and close rstCode 7, destroyed true and aborted false
2498
+ // because the request had ended its writable, then the session 'close' with no session
2499
+ // 'error'; lastStreamID above the open ids refuses nothing and matches h2lean's old
2500
+ // behaviour, which stays pinned). Without the refusal the streams lived on at rstCode
2501
+ // 0 and the graceful close waited for work the peer has already disowned.
2443
2502
  if (code === NO_ERROR) {
2503
+ if (lastStreamID < this._nextSid - 2) {
2504
+ const refused = [];
2505
+ for (const [sid, stream] of this._streams) {
2506
+ if ((sid & 1) !== 0 && sid > lastStreamID) {
2507
+ refused.push([sid, stream]);
2508
+ }
2509
+ }
2510
+ // Client-initiated ids are opened ascending, so the map's insertion order is
2511
+ // ascending and walking the list backwards is node's newest-first refusal.
2512
+ for (let i = refused.length - 1; i >= 0; i--) {
2513
+ const [sid, stream] = refused[i];
2514
+ this._dropStream(sid);
2515
+ stream._onRst(REFUSED_STREAM);
2516
+ }
2517
+ }
2444
2518
  this.close();
2445
2519
  } else {
2446
2520
  this.destroy(httpErr('ERR_HTTP2_SESSION_ERROR',
@@ -3142,31 +3216,32 @@ class ClientHttp2Session extends EventEmitter {
3142
3216
  function orderPseudo(list) {
3143
3217
  const pseudo = [];
3144
3218
  const fields = [];
3145
- for (let i = 0; i < list.length; i += 2) {
3146
- (list[i].charCodeAt(0) === 58 ? pseudo : fields).push(list[i], list[i + 1]);
3219
+ for (let i = 0; i < list.length; i += 3) {
3220
+ (list[i].charCodeAt(0) === 58 ? pseudo : fields).push(list[i], list[i + 1],
3221
+ list[i + 2]);
3147
3222
  }
3148
- const byName = (n) => {
3149
- for (let i = 0; i < pseudo.length; i += 2) {
3223
+ const byIdx = (n) => {
3224
+ for (let i = 0; i < pseudo.length; i += 3) {
3150
3225
  if (pseudo[i] === n) {
3151
- return pseudo[i + 1];
3226
+ return i;
3152
3227
  }
3153
3228
  }
3154
- return undefined;
3229
+ return -1;
3155
3230
  };
3156
3231
  const out = [];
3157
3232
  for (const n of [':method', ':path', ':scheme', ':authority', ':protocol']) {
3158
- const v = byName(n);
3159
- if (v !== undefined) {
3160
- out.push(n, v);
3233
+ const idx = byIdx(n);
3234
+ if (idx !== -1) {
3235
+ out.push(pseudo[idx], pseudo[idx + 1], pseudo[idx + 2]);
3161
3236
  }
3162
3237
  }
3163
- for (let i = 0; i < pseudo.length; i += 2) {
3238
+ for (let i = 0; i < pseudo.length; i += 3) {
3164
3239
  if (out.indexOf(pseudo[i]) === -1) {
3165
- out.push(pseudo[i], pseudo[i + 1]);
3240
+ out.push(pseudo[i], pseudo[i + 1], pseudo[i + 2]);
3166
3241
  }
3167
3242
  }
3168
- for (let i = 0; i < fields.length; i += 2) {
3169
- out.push(fields[i], fields[i + 1]);
3243
+ for (let i = 0; i < fields.length; i += 3) {
3244
+ out.push(fields[i], fields[i + 1], fields[i + 2]);
3170
3245
  }
3171
3246
  return out;
3172
3247
  }
package/lib/headers.js CHANGED
@@ -302,12 +302,12 @@ function refreshDate() {
302
302
  // need no iterator.
303
303
  // `info` marks the informational (1xx) block that additionalHeaders() sends: node applies
304
304
  // a different status rule and different error codes there, and it generates no date for it.
305
- function parse(headers, sensitive,
305
+ function parse(headers,
306
306
  { trailer = false, sendDate = false, info = false, strict = true, request = false } = {}) {
307
307
  if (headers === null || typeof headers !== 'object') {
308
308
  throw httpError('ERR_HTTP2_INVALID_HEADER_VALUE', 'headers must be an object');
309
309
  }
310
- const neverSet = sensitive || headers[KSensitiveHeaders];
310
+ const neverSet = headers[KSensitiveHeaders];
311
311
  // Inserted in one loop, not new Set(neverSet.map(...)): the map's intermediate array
312
312
  // and its closure are one allocation each per sensitive response, measured at
313
313
  // bench/micro/parse-singles.js.
@@ -476,7 +476,7 @@ function parse(headers, sensitive,
476
476
  } else {
477
477
  status = status || 200;
478
478
  if (status < 200 || status > 599) {
479
- throw httpError('ERR_HTTP2_STATUS_INVALID', `invalid status code: ${status}`);
479
+ throw httpError('ERR_HTTP2_STATUS_INVALID', `Invalid status code: ${status}`);
480
480
  }
481
481
  pseudo.push(':status', String(status));
482
482
  }
@@ -527,7 +527,7 @@ const sent = { status: 0, date: undefined, bound: 0 };
527
527
  // the table's epoch: cached bytes may name an index that a later insertion moved.
528
528
  // The returned Buffer is a view into a shared scratch block: valid until the
529
529
  // next call to block(), which is why every caller copies it immediately.
530
- function block(headers, sensitive, opts, session) {
530
+ function block(headers, opts, session) {
531
531
  const sendDate = !!(opts && opts.sendDate);
532
532
  const enc = session._encoder;
533
533
  // The second the generated date belongs to, or -1 when the block carries none. A
@@ -548,7 +548,7 @@ function block(headers, sensitive, opts, session) {
548
548
  }
549
549
 
550
550
  const update = enc.takeSizeUpdate();
551
- const parsed = parse(headers, sensitive,
551
+ const parsed = parse(headers,
552
552
  { trailer: !!(opts && opts.trailer), sendDate, info: !!(opts && opts.info),
553
553
  strict: session._strictSingle });
554
554
  sent.status = parsed.status;
@@ -634,10 +634,10 @@ function encodeAt(parsed, enc, at) {
634
634
  // so the block shares the connection's dynamic table with every other outbound block.
635
635
  // Returns a view into the shared scratch, valid until the next encode call -- the
636
636
  // caller (session.sendPushPromise) copies it into the frame immediately.
637
- function pushBlock(headers, sensitive, session) {
637
+ function pushBlock(headers, session) {
638
638
  const enc = session._encoder;
639
639
  const update = enc.takeSizeUpdate();
640
- const parsed = parse(headers, sensitive, { request: true, strict: session._strictSingle });
640
+ const parsed = parse(headers, { request: true, strict: session._strictSingle });
641
641
  const at = update === null ? 0 : update.length;
642
642
  const end = encodeAt(parsed, enc, at);
643
643
  if (at !== 0) {
package/lib/hpack.js CHANGED
@@ -1182,6 +1182,21 @@ class Encoder {
1182
1182
  this.remember(name, value, neverIndex, bytes);
1183
1183
  return this.put(dst, off, bytes);
1184
1184
  }
1185
+ // nghttp2's entropy rule (lib/nghttp2_hd.c deflate_nv): authorization always,
1186
+ // and a cookie whose value is under 20 octets with it, go out never-indexed
1187
+ // even when the application marked nothing -- "the same criteria used in
1188
+ // Firefox codebase". A node peer reports such lines under its
1189
+ // sensitiveHeaders symbol on arrival, so the forms have to match for that
1190
+ // list to agree across stacks (test/upstream/sensitive-headers.test.js).
1191
+ // An exact table match still took the indexed reference above -- nghttp2
1192
+ // keeps name_value_match under NEVER_INDEXING, and an indexed octet
1193
+ // remembers nothing anyway.
1194
+ if (name === 'authorization' || (name === 'cookie' &&
1195
+ Buffer.byteLength(value) < 20)) {
1196
+ const bytes = this.literal(name, value, 0x10);
1197
+ this.remember(name, value, neverIndex, bytes);
1198
+ return this.put(dst, off, bytes);
1199
+ }
1185
1200
  // Its name can never reach the table -- insert() is only reached past this line --
1186
1201
  // so the bytes reference nothing but static indices and are safe to cache despite
1187
1202
  // being literals.
package/lib/server.js CHANGED
@@ -136,6 +136,26 @@ function attachSession(server, socket) {
136
136
  const session = new Http2Session(socket, server._sessionOptions);
137
137
  session.server = server;
138
138
  server._sessions.add(session);
139
+ // node's connectionListener (internal/http2/core.js) arms every session accepted while
140
+ // server.timeout is set: `if (this.timeout) session.setTimeout(this.timeout, sessionOnTimeout)`.
141
+ // sessionOnTimeout emits on the SERVER -- `server.emit('timeout', this)` -- and destroys the
142
+ // session when nobody listens ("No error code, just things down"). Measured on a live node
143
+ // server with setTimeout(500) before listen: an idle connection produces one server 'timeout'
144
+ // after 500 ms of silence with a listener attached, and the client sees the session torn down
145
+ // when there is none. Calling server.setTimeout later does NOT arm sessions that already
146
+ // exist -- the check runs in the accept path only -- which test/idle-timeout.test.js pins on
147
+ // both stacks. session.setTimeout() itself is the per-connection policy and is node's
148
+ // setStreamTimeout: silence counts, every read refreshes, `setTimeout(0)` disarms.
149
+ if (server.timeout) {
150
+ session.setTimeout(server.timeout, function onSessionTimeout() {
151
+ if (this.destroyed || this.closed) {
152
+ return;
153
+ }
154
+ if (!server.emit('timeout', this)) {
155
+ this.destroy();
156
+ }
157
+ });
158
+ }
139
159
  session.on('stream', (stream, headers, options, rawHeaders) =>
140
160
  server.emit('stream', stream, headers, options, rawHeaders));
141
161
  session.on('error', (err) => {
@@ -215,14 +235,14 @@ function applyHttp2ServerApi(proto) {
215
235
  enumerable: false
216
236
  });
217
237
 
218
- // node's own Http2Server.setTimeout (internal/http2/core.js:3541) only records the value --
238
+ // node's Http2Server.setTimeout (internal/http2/core.js) only records the value --
219
239
  // `this.timeout = msecs`, the same field net.Server uses -- and attaches the callback. It
220
- // does NOT walk the sessions. Measured against node with an idle connection and
221
- // server.setTimeout(300): no 'timeout' on the session, no close, the connection simply
222
- // stays. Arming a session idle timeout for every live session (what this used to do) both
223
- // invented an event node does not emit and applied to connections that already existed,
224
- // silently skipping the ones accepted later. The per-connection idle policy is
225
- // session.setTimeout(), which is implemented on the session.
240
+ // does NOT arm the sessions that already exist. Arming happens in the accept path instead:
241
+ // connectionListener hands every session accepted while this.timeout is set a
242
+ // session.setTimeout() with a callback that reports to the server and tears the session
243
+ // down when the server has no 'timeout' listener -- that is attachSession's onSessionTimeout
244
+ // above. server.setTimeout(300) after a connection came up therefore changes nothing for it,
245
+ // which test/idle-timeout.test.js pins on both stacks.
226
246
  proto.setTimeout = function (msecs, cb) {
227
247
  this.timeout = msecs;
228
248
  if (cb !== undefined) {