h2lean 0.17.2 → 0.17.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/index.js +6 -6
- package/lib/Http2Stream.js +1328 -0
- package/lib/{client-session.js → client/Http2ClientSession.js} +28 -28
- package/lib/{client-stream.js → client/Http2ClientStream.js} +27 -782
- package/lib/{client.js → client/client.js} +4 -4
- package/lib/fast-timer.js +1 -1
- package/lib/headers.js +6 -6
- package/lib/hpack.js +26 -8
- package/lib/{session.js → server/Http2ServerSession.js} +25 -24
- package/lib/{stream.js → server/Http2ServerStream.js} +41 -1557
- package/lib/{compat.js → server/compat.js} +9 -9
- package/lib/{server.js → server/server.js} +9 -9
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// HTTP/2 client connection state machine (h2c and h2s). The mirror of lib/
|
|
1
|
+
// HTTP/2 client connection state machine (h2c and h2s). The mirror of lib/server/Http2ServerSession.js.
|
|
2
2
|
//
|
|
3
3
|
// The server file is hard-locked to its role -- it reads the client preface
|
|
4
4
|
// (session.js:771), refuses even stream ids (session.js:968) and treats the
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
// connection can make us hold.
|
|
43
43
|
// A fatal inbound frame ends the session the way node's does: GOAWAY on the wire
|
|
44
44
|
// -- flushed out of the staging batch before the socket is closed (_fatal; the
|
|
45
|
-
// server side does it the same way, lib/
|
|
45
|
+
// server side does it the same way, lib/server/Http2ServerSession.js _fatal -> sendGoaway -> _flush)
|
|
46
46
|
// -- and ERR_HTTP2_ERROR reported on the stream and on the session. Measured
|
|
47
47
|
// against node v26.12.1 on a malformed padded DATA frame
|
|
48
48
|
// (tools/probe-client-pad-bad.js) and on padded HEADERS frames
|
|
49
49
|
// (tools/probe-client-hdr-pad.js).
|
|
50
|
-
// The padded-frame rules are the server's, ported (lib/
|
|
50
|
+
// The padded-frame rules are the server's, ported (lib/server/Http2ServerSession.js _headersPrefix
|
|
51
51
|
// and _onDataFrame): a padded HEADERS whose padding does not fit is a connection
|
|
52
52
|
// error of type PROTOCOL_ERROR (RFC 9113 6.2: "If the length of the padding is
|
|
53
53
|
// the length of the frame payload or greater"), and so is a padded frame with no
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
// localSettings, duration) callback, the 'localSettings' event, the 'connect' deferral
|
|
89
89
|
// and the ten-pending-ACK limit -- is node's, measured on a live node 26 client against a
|
|
90
90
|
// raw frame-decoding peer. The server half submits only the entries the current call
|
|
91
|
-
// names too (lib/
|
|
91
|
+
// names too (lib/server/Http2ServerSession.js settings(): node's shape, measured on a live node server --
|
|
92
92
|
// two calls produced 5=32768 then 3=5), pinned as parity in
|
|
93
93
|
// test/settings-validation.test.js.
|
|
94
94
|
//
|
|
@@ -126,20 +126,20 @@
|
|
|
126
126
|
|
|
127
127
|
const { EventEmitter } = require('node:events');
|
|
128
128
|
const tls = require('node:tls');
|
|
129
|
-
const f = require('
|
|
130
|
-
const { Decoder, Encoder, HPackError } = require('
|
|
131
|
-
const FlatList = require('
|
|
132
|
-
const fastTick = require('
|
|
129
|
+
const f = require('../frames');
|
|
130
|
+
const { Decoder, Encoder, HPackError } = require('../hpack');
|
|
131
|
+
const FlatList = require('../flat-list');
|
|
132
|
+
const fastTick = require('../fast-tick');
|
|
133
133
|
// The process-wide inbound decode scratch, same shape and size as the server
|
|
134
134
|
// session's; the full why-sharing-is-safe argument lives with the server's
|
|
135
|
-
// instance (lib/
|
|
135
|
+
// instance (lib/server/Http2ServerSession.js). A module-level instance here too, not the server's
|
|
136
136
|
// list: the two never meet the same fill, and coupling the client module to the
|
|
137
137
|
// server's scratch would buy nothing.
|
|
138
138
|
const FLAT = new FlatList(64);
|
|
139
139
|
const { nullProto, isFieldName, lowerName, neverNames, CONNECTION_SPECIFIC, SINGLE_VALUE_FIELDS,
|
|
140
|
-
KSensitiveHeaders } = require('
|
|
141
|
-
const {
|
|
142
|
-
const { pieceByteAt, pieceSlice, pieceConcat, pieceEquals } = require('
|
|
140
|
+
KSensitiveHeaders } = require('../headers');
|
|
141
|
+
const { Http2ClientStream, AbortError } = require('./Http2ClientStream');
|
|
142
|
+
const { pieceByteAt, pieceSlice, pieceConcat, pieceEquals } = require('../pieces');
|
|
143
143
|
// The settings tables, defaults and buffer-path constants are the server's, reused
|
|
144
144
|
// verbatim so a client and a server in this one library never disagree about what a
|
|
145
145
|
// SETTINGS id means, what node advertises, or where the copy/reference break-even sits.
|
|
@@ -150,7 +150,7 @@ const {
|
|
|
150
150
|
proxySocketHandler, urlOrigin, parseAltSvc, parseOrigins, received, extError, checkPing,
|
|
151
151
|
pingCancelled, checkSettings, buildSubmission, submissionValues, accumulateCustom,
|
|
152
152
|
customView, checkRemoteCustomEntries
|
|
153
|
-
} = require('
|
|
153
|
+
} = require('../server/Http2ServerSession');
|
|
154
154
|
|
|
155
155
|
const {
|
|
156
156
|
DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS, PUSH_PROMISE, PING, GOAWAY,
|
|
@@ -191,7 +191,7 @@ function payloadMeaningless(method) {
|
|
|
191
191
|
|| method === 'OPTIONS' || method === 'TRACE';
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
// assertIsObject + validateSettings live in lib/
|
|
194
|
+
// assertIsObject + validateSettings live in lib/server/Http2ServerSession.js as checkSettings, beside checkPing:
|
|
195
195
|
// settings() and ping() are methods of node's Http2Session, so both halves of this library take
|
|
196
196
|
// both validators from the same place.
|
|
197
197
|
|
|
@@ -205,7 +205,7 @@ const DEFAULT_METHOD = 'GET';
|
|
|
205
205
|
// allocation per block. Only _encodeRequest writes it.
|
|
206
206
|
let sentBound = 0;
|
|
207
207
|
|
|
208
|
-
class
|
|
208
|
+
class Http2ClientSession extends EventEmitter {
|
|
209
209
|
constructor(socket, options, scheme, authority) {
|
|
210
210
|
super();
|
|
211
211
|
const opts = options || {};
|
|
@@ -861,7 +861,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
861
861
|
endStream = payloadMeaningless(method);
|
|
862
862
|
}
|
|
863
863
|
|
|
864
|
-
const stream = new
|
|
864
|
+
const stream = new Http2ClientStream(this, this._nextSid, {});
|
|
865
865
|
// node records what the application passed at this point (kSentHeaders / kRawHeaders,
|
|
866
866
|
// internal/http2/core.js:1902-1904); the getter folds it into the request map on read.
|
|
867
867
|
stream._sentSrc = headersParam;
|
|
@@ -895,7 +895,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
895
895
|
// `endAfterHeaders` -- that flag is set only on an inbound stream whose HEADERS
|
|
896
896
|
// carried END_STREAM (core.js onSessionHeaders), and a PUSH_PROMISE cannot carry
|
|
897
897
|
// it (RFC 9113 6.6), so on a client request it never reads true. The pump reads
|
|
898
|
-
// this internal one to suppress an empty trailing DATA (lib/client
|
|
898
|
+
// this internal one to suppress an empty trailing DATA (lib/client/Http2ClientStream.js).
|
|
899
899
|
stream._endOnHeaders = endStream;
|
|
900
900
|
// node's ClientHttp2Session.request() reads options.waitForTrailers to set
|
|
901
901
|
// STREAM_FLAGS_HAS_TRAILERS on the stream, which is what defers the END_STREAM
|
|
@@ -1211,7 +1211,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
1211
1211
|
}
|
|
1212
1212
|
const max = this.remoteSettings.maxFrameSize;
|
|
1213
1213
|
// END_STREAM belongs on the HEADERS frame, not on the CONTINUATION that finishes the
|
|
1214
|
-
// block -- RFC 9113 6.2 / 5.1 / 8.1, the same rule lib/
|
|
1214
|
+
// block -- RFC 9113 6.2 / 5.1 / 8.1, the same rule lib/server/Http2ServerSession.js sendHeaders states.
|
|
1215
1215
|
const es = end ? F_END_STREAM : 0;
|
|
1216
1216
|
if (block.length <= max) {
|
|
1217
1217
|
// owned=false: the batch keeps a copy, because `block` may be the encoder
|
|
@@ -1356,8 +1356,8 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
1356
1356
|
}
|
|
1357
1357
|
|
|
1358
1358
|
// Put a trailer HEADERS+END_STREAM block on the wire for a stream whose last DATA
|
|
1359
|
-
// withheld its END_STREAM flag (waitForTrailers). Called by
|
|
1360
|
-
// sendTrailers(). Mirrors what the server path does in lib/
|
|
1359
|
+
// withheld its END_STREAM flag (waitForTrailers). Called by Http2ClientStream.
|
|
1360
|
+
// sendTrailers(). Mirrors what the server path does in lib/Http2Stream.js: encode the
|
|
1361
1361
|
// field lines through the session's HPACK encoder (never a pseudo-header) and hand
|
|
1362
1362
|
// them to _sendHeaders with end=true.
|
|
1363
1363
|
_sendTrailers(stream, trailers) {
|
|
@@ -1394,7 +1394,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
1394
1394
|
if (block.length === 0) {
|
|
1395
1395
|
// An empty trailer map is not a HEADERS frame: the END_STREAM that waitForTrailers
|
|
1396
1396
|
// withheld from the body rides on a zero-length DATA instead (the same rule the
|
|
1397
|
-
// server path applies in lib/
|
|
1397
|
+
// server path applies in lib/Http2Stream.js sendTrailers, measured against node). A
|
|
1398
1398
|
// pending table-size update makes the block non-empty, so it is never dropped here.
|
|
1399
1399
|
this._frame(DATA, F_END_STREAM, stream.id, null, false);
|
|
1400
1400
|
} else {
|
|
@@ -1927,7 +1927,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
1927
1927
|
// pad length to read, which is the same connection error -- node ends the
|
|
1928
1928
|
// session with ERR_HTTP2_ERROR for both (measured,
|
|
1929
1929
|
// tools/probe-client-hdr-pad.js); the server refuses them identically
|
|
1930
|
-
// (lib/
|
|
1930
|
+
// (lib/server/Http2ServerSession.js _headersPrefix).
|
|
1931
1931
|
if (len < 1) {
|
|
1932
1932
|
return this._fatal(PROTOCOL_ERROR, 'padded HEADERS frame with an empty payload');
|
|
1933
1933
|
}
|
|
@@ -2161,7 +2161,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
2161
2161
|
// Create the pushed stream. Its writable half is pre-ended: the client never
|
|
2162
2162
|
// sends a request body for a push (node: writableEnded=true, writableFinished=true
|
|
2163
2163
|
// at the 'stream' event, measured v26.12.1).
|
|
2164
|
-
const stream = new
|
|
2164
|
+
const stream = new Http2ClientStream(this, promisedSid);
|
|
2165
2165
|
this._trackClose(stream);
|
|
2166
2166
|
stream._pushed = true;
|
|
2167
2167
|
stream.rstCode = 0;
|
|
@@ -2321,7 +2321,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
2321
2321
|
}
|
|
2322
2322
|
const sensitive = neverNames(fields, fcount, blockFlags);
|
|
2323
2323
|
// The response object is not built here: the stream builds it at the first
|
|
2324
|
-
// read (lib/client
|
|
2324
|
+
// read (lib/client/Http2ClientStream.js _onHeaders), so a client that only consumes
|
|
2325
2325
|
// the body pays no per-response object at all -- the paired marginal is in
|
|
2326
2326
|
// OPTIMIZATION.md item 48. This block still needs :status, read off the
|
|
2327
2327
|
// same field list _refuseHeaders has just vouched for: exactly one on a
|
|
@@ -2421,7 +2421,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
2421
2421
|
have.push(value);
|
|
2422
2422
|
} else if (SINGLE_VALUE_FIELDS.has(name)) {
|
|
2423
2423
|
// node keeps the first copy and ignores the rest (toHeaderObject,
|
|
2424
|
-
// SINGLE_VALUE_FIELDS in lib/
|
|
2424
|
+
// SINGLE_VALUE_FIELDS in lib/server/Http2ServerSession.js) -- the response path must read a
|
|
2425
2425
|
// repeated field the same way the server side does.
|
|
2426
2426
|
} else {
|
|
2427
2427
|
o[name] = `${have}, ${value}`;
|
|
@@ -2707,7 +2707,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
2707
2707
|
// in ascending setting-id order rather than the object's key order: measured on a live
|
|
2708
2708
|
// node 26 client against a raw peer, {headerTableSize, maxConcurrentStreams, enablePush}
|
|
2709
2709
|
// arrived as headerTableSize=8192, enablePush=0, maxConcurrentStreams=7. The server
|
|
2710
|
-
// side's settings() (lib/
|
|
2710
|
+
// side's settings() (lib/server/Http2ServerSession.js) submits only the current call's entries too --
|
|
2711
2711
|
// node's shape, measured on a live node server (two calls produced 5=32768 then 3=5).
|
|
2712
2712
|
settings(settings, cb) {
|
|
2713
2713
|
if (this.destroyed) {
|
|
@@ -2860,7 +2860,7 @@ class ClientHttp2Session extends EventEmitter {
|
|
|
2860
2860
|
// node's streams run with autoDestroy:false (measured on live node:
|
|
2861
2861
|
// _readableState.autoDestroy false on a pushed stream), so the rejection's
|
|
2862
2862
|
// destroy(err) always reaches a live Duplex and emits 'error'. h2lean's
|
|
2863
|
-
//
|
|
2863
|
+
// Http2ClientStream auto-destroys when both halves complete, and streams.destroy()
|
|
2864
2864
|
// silently drops an error handed to an already-destroyed stream -- a rejection
|
|
2865
2865
|
// that lands after a small push body has been fully read would then close the
|
|
2866
2866
|
// stream with no 'error' at all (the upstream capture-rejection block-4 shape,
|
|
@@ -3430,4 +3430,4 @@ function emitWantTrailers(stream) {
|
|
|
3430
3430
|
}
|
|
3431
3431
|
}
|
|
3432
3432
|
|
|
3433
|
-
module.exports = {
|
|
3433
|
+
module.exports = { Http2ClientSession };
|