h2lean 0.19.0 → 0.19.2
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/headers.js +1 -18
- package/lib/hpack.js +0 -5
- package/lib/server/Http2ServerSession.js +13 -2
- package/package.json +1 -1
package/lib/headers.js
CHANGED
|
@@ -738,23 +738,6 @@ function writePrepared(prep, session, dst, off) {
|
|
|
738
738
|
return off + end;
|
|
739
739
|
}
|
|
740
740
|
|
|
741
|
-
// The HPACK block for a PUSH_PROMISE payload: request-style pseudo-headers, no date,
|
|
742
|
-
// no status default, no cache (a promise is one-shot). The encoder is the session's,
|
|
743
|
-
// so the block shares the connection's dynamic table with every other outbound block.
|
|
744
|
-
// Returns a view into the shared scratch, valid until the next encode call -- the
|
|
745
|
-
// caller (session.sendPushPromise) copies it into the frame immediately.
|
|
746
|
-
function pushBlock(headers, session) {
|
|
747
|
-
const enc = session._encoder;
|
|
748
|
-
const update = enc.takeSizeUpdate();
|
|
749
|
-
const parsed = parse(headers, { request: true, strict: session._strictSingle });
|
|
750
|
-
const at = update === null ? 0 : update.length;
|
|
751
|
-
const end = encodeAt(parsed, enc, at);
|
|
752
|
-
if (at !== 0) {
|
|
753
|
-
copyInto(scratch, 0, update, 0, update.length);
|
|
754
|
-
}
|
|
755
|
-
return scratch.subarray(0, end);
|
|
756
|
-
}
|
|
757
|
-
|
|
758
741
|
// The maps node hands back as `stream.sentHeaders` and `req.sentHeaders`: the message that
|
|
759
742
|
// went out, not the object the application passed in. node copies into a null-prototype map
|
|
760
743
|
// and fills the pseudo-headers itself (prepareResponseHeadersObject, internal/http2/core.js
|
|
@@ -890,7 +873,7 @@ function requestView(src, scheme, authority) {
|
|
|
890
873
|
return view;
|
|
891
874
|
}
|
|
892
875
|
|
|
893
|
-
module.exports = { block,
|
|
876
|
+
module.exports = { block, encode, parse, prepare, writePrepared, capOf, boundOf,
|
|
894
877
|
nullProto, isFieldName, trimName, lowerName,
|
|
895
878
|
nameCacheSize, hasBadValue, neverNames, CONNECTION_SPECIFIC, KSensitiveHeaders, SINGLE_VALUE_FIELDS,
|
|
896
879
|
sent, responseView, requestView };
|
package/lib/hpack.js
CHANGED
|
@@ -1431,11 +1431,6 @@ class Encoder {
|
|
|
1431
1431
|
}
|
|
1432
1432
|
|
|
1433
1433
|
|
|
1434
|
-
indexed(index) {
|
|
1435
|
-
const b = Buffer.allocUnsafe(4);
|
|
1436
|
-
return b.subarray(0, writeInt(b, 0, index, 7, 0x80));
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
1434
|
// An indexed reference is one prefixed integer and nothing else. Writing it into
|
|
1440
1435
|
// the destination removes both the 4-octet Buffer and the memcpy from the cached
|
|
1441
1436
|
// bytes -- and the cache entry itself, which cannot survive an epoch change while
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
'use strict';
|
|
20
20
|
|
|
21
21
|
const { EventEmitter } = require('node:events');
|
|
22
|
+
const net = require('node:net');
|
|
22
23
|
const tls = require('node:tls');
|
|
23
24
|
const f = require('../frames');
|
|
24
25
|
const { Decoder, Encoder, HPackError, latin1, latin1Into } = require('../hpack');
|
|
@@ -1376,6 +1377,16 @@ class Http2ServerSession extends EventEmitter {
|
|
|
1376
1377
|
// OPTIMIZATION.md item 69: this buys memory, not request-level time.
|
|
1377
1378
|
this._pool = this._reuseBuffers
|
|
1378
1379
|
? (opts.stagingPool === undefined ? [] : opts.stagingPool) : null;
|
|
1380
|
+
// A net/TLS socket copies (or encrypts) the bytes at flush, so its write callback
|
|
1381
|
+
// is a real ownership boundary and a completed stage can be written into again.
|
|
1382
|
+
// A generic stream (stream.duplexPair, an accepted socket wrapped by the caller)
|
|
1383
|
+
// can push the very buffer we hand it to its peer and hold it until the peer
|
|
1384
|
+
// reads -- the callback then fires while the peer is still parsing, and a reused
|
|
1385
|
+
// stage would rewrite bytes already promised. Measured on a paused-duplexPair
|
|
1386
|
+
// server: 2 of 4 views were rewritten and the peer failed with ERR_HTTP2_ERROR
|
|
1387
|
+
// (frame larger than our advertised max frame size). Those sessions keep the old
|
|
1388
|
+
// allocate-per-batch path; TLSSocket is a net.Socket, so one check covers both.
|
|
1389
|
+
this._canPool = this._pool !== null && socket instanceof net.Socket;
|
|
1379
1390
|
// _pending collects the full stage buffers of a batch; _returning is the batch
|
|
1380
1391
|
// whose write callback is still owed, so only one list is in flight at a time.
|
|
1381
1392
|
this._pending = [];
|
|
@@ -1661,7 +1672,7 @@ class Http2ServerSession extends EventEmitter {
|
|
|
1661
1672
|
cap *= 2;
|
|
1662
1673
|
}
|
|
1663
1674
|
this._stageCap = Math.min(cap, MAX_OUT_BATCH);
|
|
1664
|
-
const reused = this.
|
|
1675
|
+
const reused = !this._canPool ? undefined : this._pool.pop();
|
|
1665
1676
|
this._stage = reused !== undefined && reused.length >= cap
|
|
1666
1677
|
? reused : Buffer.allocUnsafe(cap);
|
|
1667
1678
|
}
|
|
@@ -1787,7 +1798,7 @@ class Http2ServerSession extends EventEmitter {
|
|
|
1787
1798
|
// socket's no longer, so _need can write into one of them again.
|
|
1788
1799
|
const done = this._returning;
|
|
1789
1800
|
this._returning = null;
|
|
1790
|
-
if (done !== null && this.
|
|
1801
|
+
if (done !== null && this._canPool) {
|
|
1791
1802
|
for (const b of done) {
|
|
1792
1803
|
if (this._pool.length >= MAX_STAGE_POOL) {
|
|
1793
1804
|
break;
|
package/package.json
CHANGED