h2lean 0.11.1 → 0.16.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.
package/lib/client.js CHANGED
@@ -17,7 +17,7 @@
17
17
  const net = require('node:net');
18
18
  const tls = require('node:tls');
19
19
  const { ClientHttp2Session } = require('./client-session');
20
- const { strictSingleValueFields, received, outOfRangeValue } = require('./session');
20
+ const { strictSingleValueFields, received, outOfRangeValue, validateRemoteCustomSettings } = require('./session');
21
21
 
22
22
  function notImplemented(what) {
23
23
  const err = new Error(`h2lean: not implemented: ${what}`);
@@ -44,6 +44,14 @@ function connect(authority, options, listener) {
44
44
  // receive its errors. The constructor re-checks, which costs one typeof.
45
45
  strictSingleValueFields(options);
46
46
 
47
+ // remoteCustomSettings rides validateSessionOptions too: a non-array is
48
+ // ERR_INVALID_ARG_TYPE ('...must be an instance of Array'), more than
49
+ // MAX_ADDITIONAL_SETTINGS entries the plain ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS, and
50
+ // the array is copied, node's [...remoteCustomSettings]. The per-entry checks wait
51
+ // for the setup call -- the session 'error' path for a connecting socket, an
52
+ // uncaught throw out of connect() for an already-connected one (both measured).
53
+ validateRemoteCustomSettings(options);
54
+
47
55
  // core.js connect(): maxOriginSetSize is client-only and defaults to 128 (min 0).
48
56
  // It bounds how many ORIGIN frames the session accumulates into originSet before
49
57
  // destroying itself with ERR_HTTP2_TOO_MANY_ORIGINS. Validated here (before the
package/lib/compat.js CHANGED
@@ -257,14 +257,26 @@ function compatDispatch(name, arg) {
257
257
  }
258
258
 
259
259
  class Http2ServerRequest extends Readable {
260
- constructor(stream, headers, rawHeaders) {
260
+ constructor(stream) {
261
261
  super({ autoDestroy: false });
262
262
  this._stream = stream;
263
263
  // The stream's one tick route -- node's queue or the batched pump of
264
264
  // lib/fast-tick.js; the deferred callbacks of the compat layer go through it.
265
265
  this._tick = stream._tick;
266
- this._headers = headers;
267
- this._rawHeaders = rawHeaders === null ? [] : rawHeaders;
266
+ // The request object comes into being at the first read. The session builds
267
+ // it only for the 'stream' emit (lib/session.js accept path); when that did
268
+ // not happen, _headers stays undefined and _materialize() builds it from the
269
+ // stable field list the stream holds -- so a handler that only consumes the
270
+ // body and routes on req.url pays no per-request object
271
+ // (OPTIMIZATION.md item 49). The four scanned values below are read off the
272
+ // same list at accept time, one pass in lib/session.js.
273
+ const eager = stream._requestHeaders;
274
+ this._headers = eager;
275
+ this._reqFields = stream._reqFields;
276
+ this._reqSensitive = stream._reqSensitive;
277
+ this._method = stream._reqMethod;
278
+ this._path = stream._reqPath;
279
+ this._rawHeaders = undefined;
268
280
  this._trailers = { __proto__: null };
269
281
  this._rawTrailers = [];
270
282
  this._closed = false;
@@ -288,6 +300,21 @@ class Http2ServerRequest extends Readable {
288
300
  stream.on('error', onRequestError);
289
301
  }
290
302
 
303
+ // Builds the request object from the stable field list, once. After it, every
304
+ // getter reads the object -- an application that writes into req.headers
305
+ // directly must see the write through the other getters, exactly as when the
306
+ // object was already there.
307
+ _materialize() {
308
+ let h = this._headers;
309
+ if (h === undefined) {
310
+ h = this._stream.session._toObject(this._reqFields, this._reqFields.length,
311
+ this._reqSensitive);
312
+ this._headers = h;
313
+ this._stream._requestHeaders = h;
314
+ }
315
+ return h;
316
+ }
317
+
291
318
  get aborted() {
292
319
  return this._aborted;
293
320
  }
@@ -300,10 +327,18 @@ class Http2ServerRequest extends Readable {
300
327
  return this._stream;
301
328
  }
302
329
  get headers() {
303
- return this._headers;
330
+ return this._materialize();
304
331
  }
305
332
  get rawHeaders() {
306
- return this._rawHeaders;
333
+ let r = this._rawHeaders;
334
+ if (r === undefined) {
335
+ // Own copy: the field list is also the lazy build's source, so an
336
+ // application mutating rawHeaders must not corrupt it. node's rawHeaders
337
+ // is the array its parser built for this request alone.
338
+ r = this._reqFields.slice();
339
+ this._rawHeaders = r;
340
+ }
341
+ return r;
307
342
  }
308
343
  get trailers() {
309
344
  return this._trailers;
@@ -337,7 +372,7 @@ class Http2ServerRequest extends Readable {
337
372
  }
338
373
 
339
374
  get method() {
340
- return this._headers[':method'];
375
+ return this._headers !== undefined ? this._headers[':method'] : this._method;
341
376
  }
342
377
  set method(method) {
343
378
  if (typeof method !== 'string') {
@@ -346,28 +381,29 @@ class Http2ServerRequest extends Readable {
346
381
  if (method.trim() === '') {
347
382
  throw err('ERR_INVALID_ARG_VALUE', 'method must not be empty');
348
383
  }
349
- assertWritable(this._headers);
384
+ assertWritable(this._materialize());
350
385
  this._headers[':method'] = method;
351
386
  }
352
387
 
353
388
  get authority() {
354
- const auth = this._headers[':authority'];
389
+ const h = this._materialize();
390
+ const auth = h[':authority'];
355
391
  if (auth !== undefined) {
356
392
  return auth;
357
393
  }
358
- const host = this._headers.host;
394
+ const host = h.host;
359
395
  return host === undefined ? undefined : String(host).replace(/:[\d]+$/, '');
360
396
  }
361
397
 
362
398
  get scheme() {
363
- return this._headers[':scheme'];
399
+ return this._materialize()[':scheme'];
364
400
  }
365
401
 
366
402
  get url() {
367
- return this._headers[':path'];
403
+ return this._headers !== undefined ? this._headers[':path'] : this._path;
368
404
  }
369
405
  set url(url) {
370
- assertWritable(this._headers);
406
+ assertWritable(this._materialize());
371
407
  this._headers[':path'] = url;
372
408
  }
373
409
 
@@ -463,9 +499,7 @@ class Http2ServerResponse extends Stream {
463
499
  finishEmitted: false,
464
500
  sendDate: true,
465
501
  statusCode: 200,
466
- headRequest: stream._requestHeaders
467
- ? stream._requestHeaders[':method'] === 'HEAD'
468
- : false
502
+ headRequest: stream._reqMethod === 'HEAD'
469
503
  };
470
504
  // A fast null-prototype map, not a { __proto__: null } literal: the
471
505
  // response's headers are written once and read once per response, and the
@@ -920,14 +954,16 @@ class Http2ServerResponse extends Stream {
920
954
  }
921
955
  }
922
956
 
923
- // node's default 'stream' handler. Called with the server as `this`.
924
- function onServerStream(stream, headers, options, rawHeaders) {
957
+ // node's default 'stream' handler, reworked for the lazy request object: the
958
+ // session calls it directly with the stream, whose stable field list the
959
+ // request builds from at the first read (OPTIMIZATION.md item 49). Called with
960
+ // the server as `this`.
961
+ function onServerStream(stream) {
925
962
  const server = this;
926
- const request = new Http2ServerRequest(stream, headers, rawHeaders);
927
- stream._requestHeaders = headers;
963
+ const request = new Http2ServerRequest(stream);
928
964
  const response = new Http2ServerResponse(stream);
929
965
 
930
- const method = headers[':method'];
966
+ const method = stream._reqMethod;
931
967
  if (method === 'CONNECT') {
932
968
  if (!server.emit('connect', request, response)) {
933
969
  response.statusCode = 405;
@@ -936,8 +972,18 @@ function onServerStream(stream, headers, options, rawHeaders) {
936
972
  return;
937
973
  }
938
974
 
939
- if (headers.expect !== undefined) {
940
- if (headers.expect === '100-continue') {
975
+ // expect is not in SINGLE_VALUE_FIELDS (lib/headers.js), so repeated values
976
+ // join the way _toObject joins them; the scan reads the stable list the
977
+ // object has not been built from.
978
+ const fields = stream._reqFields;
979
+ let expect;
980
+ for (let i = 0; i < fields.length; i += 2) {
981
+ if (fields[i] === 'expect') {
982
+ expect = expect === undefined ? fields[i + 1] : `${expect}, ${fields[i + 1]}`;
983
+ }
984
+ }
985
+ if (expect !== undefined) {
986
+ if (expect === '100-continue') {
941
987
  if (server.listenerCount('checkContinue') > 0) {
942
988
  server.emit('checkContinue', request, response);
943
989
  } else {
package/lib/frames.js CHANGED
@@ -118,6 +118,30 @@ function trimPadding(pieces) {
118
118
  return total;
119
119
  }
120
120
 
121
+ // Move src[srcOff, srcEnd) into dst at dstOff, choosing by length. buffer.copy is not
122
+ // a bare memmove: copyImpl runs two ArrayBufferIsView tests, three integer
123
+ // normalizations and the range checks in the JS layer first, and below a few tens of
124
+ // octets that floor is the whole cost. Measured (OPTIMIZATION.md item 56, node
125
+ // v26.12.1, unaligned sources).
126
+ //
127
+ // Bounds are exact and the caller owns them: unlike copy, the stores do not clamp to
128
+ // src.length, so passing a range that runs off the end writes zeros rather than
129
+ // truncating. Every call site here has its range checked (a frame length validated
130
+ // before the payload is touched, or a length the caller computed itself). No return
131
+ // value: the two branches have different ones and no caller needs either.
132
+ const COPY_LOOP_MAX = 32;
133
+
134
+ function copyInto(dst, dstOff, src, srcOff, srcEnd) {
135
+ const n = srcEnd - srcOff;
136
+ if (n < COPY_LOOP_MAX) {
137
+ for (let i = 0; i < n; i++) {
138
+ dst[dstOff + i] = src[srcOff + i];
139
+ }
140
+ return;
141
+ }
142
+ src.copy(dst, dstOff, srcOff, srcEnd);
143
+ }
144
+
121
145
  module.exports = {
122
146
  PREFACE, PREFACE_LEN, HEADER_LEN,
123
147
  DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS, PUSH_PROMISE, PING, GOAWAY,
@@ -129,7 +153,7 @@ module.exports = {
129
153
  ERROR_NAMES,
130
154
  ST_IDLE, ST_OPEN, ST_RESERVED_LOCAL, ST_RESERVED_REMOTE,
131
155
  ST_HALF_CLOSED_LOCAL, ST_HALF_CLOSED_REMOTE, ST_CLOSED,
132
- readHeader, writeHeader, trimPadding,
156
+ readHeader, writeHeader, trimPadding, copyInto,
133
157
  get FH_LEN() {
134
158
  return FH_LEN;
135
159
  },
package/lib/headers.js CHANGED
@@ -14,6 +14,7 @@
14
14
  'use strict';
15
15
 
16
16
  const { Encoder } = require('./hpack');
17
+ const { copyInto } = require('./frames');
17
18
  const { sensitiveHeaders: KSensitiveHeaders } = require('node:http2');
18
19
 
19
20
  // A header map with no prototype.
@@ -570,14 +571,14 @@ function block(headers, opts, session) {
570
571
  const at = update === null ? 0 : update.length;
571
572
  const end = encodeAt(parsed, enc, at);
572
573
  if (at !== 0) {
573
- update.copy(scratch, 0);
574
+ copyInto(scratch, 0, update, 0, update.length);
574
575
  }
575
576
  if (cacheable && enc.epoch === epoch && !enc.unsettled) {
576
577
  // a cached block has to outlive the scratch, so only the cached path copies --
577
578
  // allocUnsafe, not Buffer.from(subarray): at the sizes a response block has the
578
579
  // pool copy is the cheaper allocation (OPTIMIZATION.md item 18)
579
580
  const bytes = Buffer.allocUnsafe(end - at);
580
- scratch.copy(bytes, 0, at, end);
581
+ copyInto(bytes, 0, scratch, at, end);
581
582
  session._blocks.set(headers,
582
583
  { bytes, epoch: enc.epoch, stamp, status: parsed.status, date: parsed.genDate,
583
584
  bound: sent.bound });
@@ -641,7 +642,7 @@ function pushBlock(headers, session) {
641
642
  const at = update === null ? 0 : update.length;
642
643
  const end = encodeAt(parsed, enc, at);
643
644
  if (at !== 0) {
644
- update.copy(scratch, 0);
645
+ copyInto(scratch, 0, update, 0, update.length);
645
646
  }
646
647
  return scratch.subarray(0, end);
647
648
  }
package/lib/pieces.js CHANGED
@@ -20,6 +20,8 @@
20
20
  // the padding off a frame passes the trimmed offsets.
21
21
  'use strict';
22
22
 
23
+ const { copyInto } = require('./frames');
24
+
23
25
  // How many octets the views hold together.
24
26
  function piecesLength(pieces) {
25
27
  let n = 0;
@@ -84,7 +86,7 @@ function pieceCopyTo(dst, dstOff, pieces, from, to) {
84
86
  if (end > from && off < to) {
85
87
  const a = from > off ? from - off : 0;
86
88
  const b = to < end ? to - off : p.length;
87
- p.copy(dst, dstOff + written, a, b);
89
+ copyInto(dst, dstOff + written, p, a, b);
88
90
  written += b - a;
89
91
  }
90
92
  off = end;
package/lib/server.js CHANGED
@@ -74,7 +74,8 @@
74
74
  const net = require('node:net');
75
75
  const tls = require('node:tls');
76
76
  const { EventEmitter } = require('node:events');
77
- const { Http2Session, OUR_DEFAULTS, strictSingleValueFields } = require('./session');
77
+ const { Http2Session, OUR_DEFAULTS, strictSingleValueFields, checkSettings,
78
+ validateRemoteCustomSettings } = require('./session');
78
79
  const { onServerStream, Http2ServerRequest, Http2ServerResponse, describeType } = require('./compat');
79
80
 
80
81
  const kCompat = Symbol('h2lean.compatListener');
@@ -92,7 +93,14 @@ function notImplemented(what) {
92
93
  }
93
94
 
94
95
  function initHttp2Server(server, options) {
95
- const opts = options || {};
96
+ // node's initializeOptions works on its own copy of the option bag -- it never writes
97
+ // back to the caller's object -- and validateSessionOptions then copies
98
+ // remoteCustomSettings ([...remoteCustomSettings]). Both are observable: measured on a
99
+ // live node server, mutating the caller's array after createServer leaves every session
100
+ // created afterwards untouched, while handing the session the original reference made
101
+ // the next accepted session throw on the entry the caller pushed.
102
+ const opts = { ...(options || {}) };
103
+ validateRemoteCustomSettings(opts);
96
104
  server.settings = { ...OUR_DEFAULTS, ...opts.settings };
97
105
  server._sessionOptions = {
98
106
  settings: server.settings,
@@ -123,10 +131,32 @@ function initHttp2Server(server, options) {
123
131
  // The server `origins` option: each session sends one ORIGIN frame with these origins at
124
132
  // connect. node only does it when the value is an array (core.js setupHandle), so it rides
125
133
  // through unvalidated and Http2Session._start applies the same Array.isArray test.
126
- origins: opts.origins
134
+ origins: opts.origins,
135
+ // Unbounded-work-per-peer guards: ride through raw, resolved in the session constructor.
136
+ maxOutstandingPings: opts.maxOutstandingPings,
137
+ maxSessionInvalidFrames: opts.maxSessionInvalidFrames,
138
+ maxSessionRejectedStreams: opts.maxSessionRejectedStreams,
139
+ // Connection-level send window override (separate from per-stream initialWindowSize).
140
+ connectionWindowSize: opts.connectionWindowSize,
141
+ // Validated and copied above, where node's initializeOptions runs
142
+ // validateSessionOptions -- synchronously, at createServer. The per-entry checks
143
+ // wait for the session constructor (setupHandle), where node runs them per
144
+ // connection, and a refused value throws uncaught at accept.
145
+ remoteCustomSettings: opts.remoteCustomSettings
127
146
  };
128
147
  server._sessions = new Set();
129
148
  server[kCompat] = null;
149
+ // node arms its compat layer through a newListener hook (setupCompat,
150
+ // internal/http2/core.js) rather than by wrapping the registration methods, so
151
+ // on()/once()/addListener() all count. The same hook arms the 'stream' bridge,
152
+ // which the direct compat delivery below depends on knowing about.
153
+ server.on('newListener', (event) => {
154
+ if (event === 'request') {
155
+ server._setupCompat();
156
+ } else if (event === 'stream') {
157
+ server._setupStreamBridge();
158
+ }
159
+ });
130
160
  // node validates this as uint32 and defaults it to 10000 (initializeOptions, core.js);
131
161
  // it bounds how long an unknown-protocol socket may sit after the 403 text.
132
162
  if (opts.unknownProtocolTimeout !== undefined &&
@@ -169,8 +199,25 @@ function attachSession(server, socket) {
169
199
  }
170
200
  });
171
201
  }
172
- session.on('stream', (stream, headers, options, rawHeaders) =>
173
- server.emit('stream', stream, headers, options, rawHeaders));
202
+ // The session->server bridge for the application's 'stream' listeners, and the
203
+ // compat delivery decision. Two shapes, exactly one per session: with 'stream'
204
+ // listeners the session emits the built object and compat rides the server's
205
+ // 'stream' event behind the bridge (the listener order node has, since node
206
+ // subscribes onServerStream on the server); without them the session calls the
207
+ // compat entry directly with the stable field list, which is what lets the
208
+ // request object come into being at the first req.headers read instead of at
209
+ // frame decode (OPTIMIZATION.md item 49).
210
+ if (server._streamBridgeArmed === true) {
211
+ session.on('stream', (stream, headers, options, rawHeaders) =>
212
+ server.emit('stream', stream, headers, options, rawHeaders));
213
+ }
214
+ if (server[kCompat] !== null) {
215
+ if (server._streamBridgeArmed === true) {
216
+ server._armCompatChain();
217
+ } else {
218
+ session._onStreamCompat = server[kCompat];
219
+ }
220
+ }
174
221
  session.on('error', (err) => {
175
222
  if (server.listenerCount('sessionError') > 0) {
176
223
  server.emit('sessionError', err);
@@ -188,28 +235,57 @@ function applyHttp2ServerApi(proto) {
188
235
 
189
236
  // node instantiates the compat req/res only when the application asks for
190
237
  // them: a plain createServer() with a 'stream' handler never pays for two
191
- // objects per request. Adding the first 'request' listener arms it.
238
+ // objects per request. Adding the first 'request' listener arms it, via the
239
+ // newListener hook node itself uses (setupCompat, internal/http2/core.js).
192
240
  proto._setupCompat = function () {
193
241
  if (this[kCompat] !== null) {
194
242
  return this;
195
243
  }
196
244
  this[kCompat] = onServerStream.bind(this);
197
245
  this._sessionOptions.compat = true;
246
+ // Both delivery shapes need the raw field list: the chain hands it out as
247
+ // the fourth 'stream' argument, the direct call builds from it. A session
248
+ // that already carries the 'stream' bridge keeps compat on the server's
249
+ // 'stream' event; the rest take the direct call.
198
250
  for (const session of this._sessions) {
199
251
  session._wantRaw = true;
200
252
  }
201
- return proto[kTransportOn].call(this, 'stream', this[kCompat]);
253
+ if (this._streamBridgeArmed === true) {
254
+ this._armCompatChain();
255
+ } else {
256
+ for (const session of this._sessions) {
257
+ session._onStreamCompat = this[kCompat];
258
+ }
259
+ }
260
+ return this;
202
261
  };
203
262
 
204
- proto.on = function (event, listener) {
205
- if (event === 'request') {
206
- this._setupCompat();
263
+ // The bridge for the application's own 'stream' listeners, attached to the
264
+ // sessions that already exist (new sessions take it at accept, see
265
+ // attachSession). Arming it also moves the sessions that were in direct
266
+ // compat delivery onto the chain, so the listener order on the server's
267
+ // 'stream' event is the one node has however the two registrations interleave.
268
+ proto._setupStreamBridge = function () {
269
+ if (this._streamBridgeArmed === true) {
270
+ return this;
271
+ }
272
+ this._streamBridgeArmed = true;
273
+ for (const session of this._sessions) {
274
+ session.on('stream', (stream, headers, options, rawHeaders) =>
275
+ this.emit('stream', stream, headers, options, rawHeaders));
276
+ session._onStreamCompat = null;
277
+ }
278
+ if (this[kCompat] !== null) {
279
+ this._armCompatChain();
207
280
  }
208
- return proto[kTransportOn].call(this, event, listener);
281
+ return this;
209
282
  };
210
283
 
211
- proto.addListener = function (event, listener) {
212
- return this.on(event, listener);
284
+ proto._armCompatChain = function () {
285
+ if (this._compatChained !== true) {
286
+ this._compatChained = true;
287
+ proto[kTransportOn].call(this, 'stream', this[kCompat]);
288
+ }
213
289
  };
214
290
 
215
291
  proto.close = function (cb) {
@@ -267,20 +343,21 @@ function applyHttp2ServerApi(proto) {
267
343
  return this;
268
344
  };
269
345
 
270
- // node's Http2Server.updateSettings() (internal/http2/core.js, next to its setTimeout) only
271
- // merges into the server's own settings object -- it does not walk the live sessions. That
272
- // is exactly what the wire shows: after updateSettings({maxConcurrentStreams: 7}) the next
273
- // connection is sent SETTINGS(3)=7 while an established session keeps the values it was
274
- // opened with. `_sessionOptions.settings` is the object sessions are built from, so pointing
275
- // it at the merged copy gives the same reach: new connections, no effect on old ones.
346
+ // node's Http2Server.updateSettings() (internal/http2/core.js, next to its setTimeout)
347
+ // runs assertIsObject + validateSettings and merges shallowly into the server's own
348
+ // settings object -- it does not walk the live sessions. That is exactly what the wire
349
+ // shows: after updateSettings({maxConcurrentStreams: 7}) the next connection is sent
350
+ // SETTINGS(3)=7 while an established session keeps the values it was opened with.
351
+ // checkSettings carries the customSettings checks too; the merged bag's customs reach
352
+ // the next session's initial submission through its constructor, where the packer
353
+ // checks throw uncaught at accept, the way node's setupHandle throws.
276
354
  proto.updateSettings = function (settings) {
277
- if (settings === null || typeof settings !== 'object') {
278
- throw new TypeError('settings must be an object');
279
- }
355
+ checkSettings(settings);
280
356
  this.settings = { ...this.settings, ...settings };
281
357
  this._sessionOptions.settings = this.settings;
282
358
  // the values merged here become promises to the next peer, so they join the advertisement;
283
- // first-seen order is kept, and it is the order the SETTINGS entries go out in
359
+ // the set is only the membership of the next session's initial frame, whose entries go out
360
+ // in ascending setting-id order (measured on node, see submissionValues in lib/session.js)
284
361
  this._sessionOptions.advertised = [...new Set(
285
362
  [...this._sessionOptions.advertised, ...Object.keys(settings)])];
286
363
  return this;
@@ -425,6 +502,19 @@ class Http2SecureServer extends tls.Server {
425
502
  const opts = options || {};
426
503
  super(alpnOptions(opts));
427
504
  initHttp2Server(this, opts);
505
+ // node's onErrorSecureServerSession (internal/http2/core.js, subscribed in the
506
+ // Http2SecureServer constructor): the tls.Server machinery emits 'tlsClientError'
507
+ // (err, tlsSocket) -- onSocketTLSError for a failed handshake, and a synthesized
508
+ // ConnResetException('socket hang up') from onSocketClose when the client
509
+ // disconnects before the handshake completes -- and the secure server re-emits it
510
+ // as 'clientError' (err, socket), destroying the socket with the error when
511
+ // nothing listens for 'clientError'. h2lean inherits the 'tlsClientError'
512
+ // emission from tls.Server; this bridge is the piece that was missing.
513
+ this.on('tlsClientError', (err, socket) => {
514
+ if (!this.emit('clientError', err, socket)) {
515
+ socket.destroy(err);
516
+ }
517
+ });
428
518
  if (opts.allowHTTP1 === true) {
429
519
  initHttp1Fallback(this, opts);
430
520
  }
@@ -491,11 +581,17 @@ function createSecureServer(options, onRequestHandler) {
491
581
  // net.Socket for h2c. node does NOT check alpnProtocol here (the ALPN verdict is
492
582
  // the caller's, not the handshake's), and neither do we; a still-connecting socket
493
583
  // is waited for by the session constructor. The options h2lean implements are
494
- // validated the way initializeOptions validates them; the rest (remoteCustomSettings,
495
- // maxSessionInvalidFrames, connectionWindowSize, origins) concern features h2lean
496
- // does not implement and are ignored here exactly as they are at createServer. The one
497
- // surface difference (node's JSStreamSocket wrap of a generic Duplex, so 'connect's second
498
- // argument differs there) is written up in this file's header.
584
+ // validated the way initializeOptions validates them -- remoteCustomSettings here,
585
+ // synchronously, like every initializeOptions caller; the session constructor then
586
+ // runs the per-entry checks and the settings packer unguarded, where node's
587
+ // setupHandle throw escapes the call. The rest (origins) concerns a feature
588
+ // h2lean does implement but has no server-level ORIGIN frame to send, so it rides
589
+ // through raw and is applied per-session. Unbounded-work-per-peer guards
590
+ // (maxSessionInvalidFrames, maxSessionRejectedStreams, maxOutstandingPings,
591
+ // connectionWindowSize) also ride through raw and are resolved in the session
592
+ // constructor. The one surface difference
593
+ // (node's JSStreamSocket wrap of a generic Duplex, so 'connect's second argument
594
+ // differs there) is written up in this file's header.
499
595
  function performServerHandshake(socket, options) {
500
596
  if (options !== undefined &&
501
597
  (options === null || typeof options !== 'object' || Array.isArray(options))) {
@@ -513,6 +609,7 @@ function performServerHandshake(socket, options) {
513
609
  throw err;
514
610
  }
515
611
  strictSingleValueFields(opts);
612
+ validateRemoteCustomSettings(opts);
516
613
  // opts.settings carries only what the application asked for, and the session's
517
614
  // _advertised defaults to Object.keys(opts.settings) -- so the first SETTINGS frame
518
615
  // advertises exactly those, empty when nothing was asked, the way node's does.