h2lean 0.17.3 → 0.17.5

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.
@@ -10,7 +10,7 @@
10
10
  // per read(). A paused request buffers in memory instead of slowing the peer down.
11
11
  // * res.cork()/uncork() (and writableCorked/writableHighWaterMark) delegate to the wrapped
12
12
  // stream, exactly as node's compat does (`cork(){ this[kStream].cork(); }`). That stream's
13
- // cork is a counting stub, not Writable's buffering cork (lib/stream.js): h2lean coalesces a
13
+ // cork is a counting stub, not Writable's buffering cork (lib/Http2Stream.js): h2lean coalesces a
14
14
  // synchronous burst into one write() but sends immediately while corked, where node defers
15
15
  // the DATA until the count reaches 0. Measured on a live node server, so the response
16
16
  // inherits the same cross-tick deferral divergence (test/cork-parity.test.js).
@@ -44,7 +44,7 @@
44
44
  // between requests whose header block is identical, so req.url = ... and
45
45
  // req.method = ... throw instead of rewriting the request.
46
46
  // * the compat layer's handlers are not subscriptions on the stream: the stream
47
- // calls them through one dispatch function (lib/stream.js, emit()), so
47
+ // calls them through one dispatch function (lib/Http2Stream.js, emit()), so
48
48
  // stream.listenerCount('close') and friends report fewer listeners than they
49
49
  // do on node, whose compat layer subscribes to the same events
50
50
  // (internal/http2/compat, the stream.on() calls in the request and the
@@ -54,7 +54,7 @@
54
54
 
55
55
  const { Readable, Stream } = require('node:stream');
56
56
 
57
- const { nullProto, trimName, isFieldName } = require('./headers');
57
+ const { nullProto, trimName, isFieldName } = require('../headers');
58
58
 
59
59
  function err(code, msg) {
60
60
  const e = new Error(msg);
@@ -258,7 +258,7 @@ function onRequestTimeout() {
258
258
  }
259
259
  }
260
260
 
261
- // The compat layer's handlers, called by the stream (lib/stream.js) when it emits
261
+ // The compat layer's handlers, called by the stream (lib/Http2Stream.js) when it emits
262
262
  // an event, with the stream as `this`. The order is the order the subscriptions had:
263
263
  // the request's handler before the response's for the three events both of them
264
264
  // answer, and both before the application's own listeners.
@@ -303,12 +303,12 @@ class Http2ServerRequest extends Readable {
303
303
  // lib/fast-tick.js; the deferred callbacks of the compat layer go through it.
304
304
  this._tick = stream._tick;
305
305
  // The request object comes into being at the first read. The session builds
306
- // it only for the 'stream' emit (lib/session.js accept path); when that did
306
+ // it only for the 'stream' emit (lib/server/Http2ServerSession.js accept path); when that did
307
307
  // not happen, _headers stays undefined and _materialize() builds it from the
308
308
  // stable field list the stream holds -- so a handler that only consumes the
309
309
  // body and routes on req.url pays no per-request object
310
310
  // (OPTIMIZATION.md item 49). The four scanned values below are read off the
311
- // same list at accept time, one pass in lib/session.js.
311
+ // same list at accept time, one pass in lib/server/Http2ServerSession.js.
312
312
  const eager = stream._requestHeaders;
313
313
  this._headers = eager;
314
314
  this._reqFields = stream._reqFields;
@@ -331,7 +331,7 @@ class Http2ServerRequest extends Readable {
331
331
  // the compat layer's handlers through one dispatch function, which costs
332
332
  // one call per event instead of a subscription per event -- subscriptions
333
333
  // are an order of magnitude dearer per request (OPTIMIZATION.md item 5;
334
- // lib/stream.js, emit()). The 'error' handler stays a
334
+ // lib/Http2Stream.js, emit()). The 'error' handler stays a
335
335
  // subscription, because a stream the application never listens to must not
336
336
  // throw on an unhandled 'error' -- the subscription is what keeps that from
337
337
  // happening.
@@ -401,7 +401,7 @@ class Http2ServerRequest extends Readable {
401
401
  // to the stream. h2lean instead hands out the real socket -- it is smaller and answers the
402
402
  // same questions (remoteAddress), but a `.write()` that node refuses succeeds here. KNOWN
403
403
  // DIVERGENCE, and separate from the session surface. The session reference is cleared when the
404
- // stream dies (lib/stream.js _destroy, node core.js:2546), so the socket goes with it.
404
+ // stream dies (lib/Http2Stream.js _destroy, node core.js:2546), so the socket goes with it.
405
405
  get socket() {
406
406
  const session = this._stream.session;
407
407
  return session === undefined ? undefined : session._socket;
@@ -978,7 +978,7 @@ class Http2ServerResponse extends Stream {
978
978
 
979
979
  // node's compat response delegates corking to the stream it wraps (internal/http2/compat.js:
980
980
  // `cork(){ this[kStream].cork(); }`, and writableCorked/writableHighWaterMark read the stream's
981
- // Writable side). h2lean's stream cork is a counting stub (lib/stream.js), so res.cork()/uncork()
981
+ // Writable side). h2lean's stream cork is a counting stub (lib/Http2Stream.js), so res.cork()/uncork()
982
982
  // inherit its cross-tick deferral divergence -- measured against a live node server and pinned in
983
983
  // test/cork-parity.test.js.
984
984
  cork() {
@@ -1,5 +1,5 @@
1
1
  // Server front door, both transports: h2c on a net.Server and h2s on a tls.Server.
2
- // This file owns the listening socket, one Http2Session per connection, and the
2
+ // This file owns the listening socket, one Http2ServerSession per connection, and the
3
3
  // decision of whether the compat (req, res) layer is instantiated at all.
4
4
  //
5
5
  // Connection-lifetime surface, measured against node 26 rather than against its
@@ -36,7 +36,7 @@
36
36
  // node's session survives close() until its graceful close completes (internal/http2/core.js:
37
37
  // handle.ongracefulclosecomplete -> kMaybeDestroy), so it can still read -- and report -- the
38
38
  // peer's answer to the GOAWAY we just sent. h2lean destroys the session as soon as that GOAWAY
39
- // is written (lib/session.js: close() -> _maybeFinishClose), but its socket stays readable
39
+ // is written (lib/server/Http2ServerSession.js: close() -> _maybeFinishClose), but its socket stays readable
40
40
  // until the write is flushed, so the answer is read there too. The two therefore disagree
41
41
  // about ONE event -- the 'goaway' the peer's answer produces -- and only inside a window:
42
42
  // measured with tools/probe-goaway-echo.js, node's outcome moves with the load (40 of 40
@@ -74,8 +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, checkSettings,
78
- validateRemoteCustomSettings } = require('./session');
77
+ const { Http2ServerSession, OUR_DEFAULTS, strictSingleValueFields, checkSettings,
78
+ validateRemoteCustomSettings } = require('./Http2ServerSession');
79
79
  const { onServerStream, Http2ServerRequest, Http2ServerResponse, describeType } = require('./compat');
80
80
 
81
81
  const kCompat = Symbol('h2lean.compatListener');
@@ -107,7 +107,7 @@ function initHttp2Server(server, options) {
107
107
  // Which values the application asked for. server.settings is what the session's guards read,
108
108
  // this list is what the peer is told, and the two are deliberately not the same object: node
109
109
  // advertises only what was set (created with no options, its SETTINGS frame is empty), and an
110
- // advertised number decides how hard peers drive the connection. See Http2Session._advertised.
110
+ // advertised number decides how hard peers drive the connection. See Http2ServerSession._advertised.
111
111
  advertised: Object.keys(opts.settings || {}),
112
112
  // There is no copy to opt out of: a DATA payload reaches the application
113
113
  // either as a view of the buffer node read off the socket or as a buffer
@@ -130,7 +130,7 @@ function initHttp2Server(server, options) {
130
130
  batchNextTick: opts.batchNextTick,
131
131
  // The server `origins` option: each session sends one ORIGIN frame with these origins at
132
132
  // connect. node only does it when the value is an array (core.js setupHandle), so it rides
133
- // through unvalidated and Http2Session._start applies the same Array.isArray test.
133
+ // through unvalidated and Http2ServerSession._start applies the same Array.isArray test.
134
134
  origins: opts.origins,
135
135
  // Unbounded-work-per-peer guards: ride through raw, resolved in the session constructor.
136
136
  maxOutstandingPings: opts.maxOutstandingPings,
@@ -176,7 +176,7 @@ function initHttp2Server(server, options) {
176
176
 
177
177
  // Turns an accepted socket -- plain or already decrypted -- into a session.
178
178
  function attachSession(server, socket) {
179
- const session = new Http2Session(socket, server._sessionOptions);
179
+ const session = new Http2ServerSession(socket, server._sessionOptions);
180
180
  session.server = server;
181
181
  server._sessions.add(session);
182
182
  // node's connectionListener (internal/http2/core.js) arms every session accepted while
@@ -357,7 +357,7 @@ function applyHttp2ServerApi(proto) {
357
357
  this._sessionOptions.settings = this.settings;
358
358
  // the values merged here become promises to the next peer, so they join the advertisement;
359
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)
360
+ // in ascending setting-id order (measured on node, see submissionValues in lib/server/Http2ServerSession.js)
361
361
  this._sessionOptions.advertised = [...new Set(
362
362
  [...this._sessionOptions.advertised, ...Object.keys(settings)])];
363
363
  return this;
@@ -614,7 +614,7 @@ function performServerHandshake(socket, options) {
614
614
  // _advertised defaults to Object.keys(opts.settings) -- so the first SETTINGS frame
615
615
  // advertises exactly those, empty when nothing was asked, the way node's does.
616
616
  // No server means no compat layer: the session emits 'stream', never 'request'.
617
- return new Http2Session(socket, opts);
617
+ return new Http2ServerSession(socket, opts);
618
618
  }
619
619
 
620
620
  // node's routing for an async listener's rejection when EventEmitter
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h2lean",
3
- "version": "0.17.3",
3
+ "version": "0.17.5",
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": [