h2lean 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/lib/server.js +21 -8
  2. package/package.json +1 -1
package/lib/server.js CHANGED
@@ -40,10 +40,12 @@
40
40
  // and http's _connectionListener is bound to it -- so one emitter and one listener list
41
41
  // carry both protocols. Those symbols are not reachable from node:http, so the fallback
42
42
  // here is an embedded http.Server that never listens, fed the sockets the ALPN verdict
43
- // hands it, with a newListener mirror (node's own setupCompat hook) carrying the
44
- // application's request/upgrade/clientError/... listeners onto it. Three written-down
45
- // consequences of that model: a removeListener does not unmirror (node has no such seam);
46
- // the embedded server's own idle-connection bookkeeping never starts, because its
43
+ // hands it, with a newListener/removeListener mirror (node's own setupCompat hook) carrying
44
+ // the application's request/upgrade/clientError/... listeners onto it and taking them
45
+ // back off. Two written-down consequences of that model: removeAllListeners fires neither
46
+ // hook, so listeners removed that way stay mirrored (node has no such seam at all, and
47
+ // there is no per-listener event to hook); the embedded server's own idle-connection
48
+ // bookkeeping never starts, because its
47
49
  // 'listening' never fires, so the handed-off sockets are tracked here and close() shuts
48
50
  // the idle keep-alive ones down while letting a response in flight finish (node waits
49
51
  // through net.Server's own bookkeeping); and an unknownProtocol socket -- no ALPN, no
@@ -272,10 +274,11 @@ const HTTP1_MIRROR = new Set([
272
274
  // HTTP/1 options into private fields of the Http2SecureServer itself, so there is no
273
275
  // second server object and no second listener list. Those symbols are not reachable
274
276
  // from node:http, so the fallback here is a real http.Server that never listens and
275
- // receives the sockets the ALPN verdict hands it. Consequences written down in the
276
- // header comment: the mirror is one-way (removeListener does not unmirror), and the
277
- // embedded server's own connection bookkeeping never starts because 'listening' never
278
- // fires -- the handed-off sockets are tracked here instead.
277
+ // receives the sockets the ALPN verdict hands it. The mirror tracks removals too (the
278
+ // handler below); removeAllListeners fires neither hook and is the one seam the mirror
279
+ // cannot follow -- recorded in the header comment. The embedded server's own connection
280
+ // bookkeeping never starts because 'listening' never fires -- the handed-off sockets are
281
+ // tracked here instead.
279
282
  function initHttp1Fallback(server, opts) {
280
283
  const http = require('node:http');
281
284
  // DEP0202 (doc/api/deprecations.md): the top-level Http1IncomingMessage and
@@ -296,6 +299,16 @@ function initHttp1Fallback(server, opts) {
296
299
  server._http1.on(event, listener);
297
300
  }
298
301
  });
302
+ server.on('removeListener', (event, listener) => {
303
+ // the other half of the mirror: node serves both protocols from ONE listener list,
304
+ // so taking a listener off the server takes it off the HTTP/1 side too. A once
305
+ // listener's self-removal after its single fire passes through here as well and
306
+ // drops the (now inert) wrapper from _http1. removeAllListeners fires neither
307
+ // hook -- the one seam the mirror cannot follow, header comment.
308
+ if (HTTP1_MIRROR.has(event)) {
309
+ server._http1.removeListener(event, listener);
310
+ }
311
+ });
299
312
  // Per-socket activity, so close() can tell an idle keep-alive socket (destroy it,
300
313
  // the way closeIdleConnections does on node) from one with a response in flight.
301
314
  server._http1.on('request', (req, res) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h2lean",
3
- "version": "0.2.0",
3
+ "version": "0.2.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": [