h2lean 0.11.1 → 0.11.3
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/compat.js +68 -22
- package/lib/server.js +67 -10
- package/lib/session.js +66 -17
- package/lib/stream.js +53 -14
- package/package.json +1 -1
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
|
|
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
|
-
|
|
267
|
-
|
|
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.
|
|
330
|
+
return this._materialize();
|
|
304
331
|
}
|
|
305
332
|
get rawHeaders() {
|
|
306
|
-
|
|
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.
|
|
384
|
+
assertWritable(this._materialize());
|
|
350
385
|
this._headers[':method'] = method;
|
|
351
386
|
}
|
|
352
387
|
|
|
353
388
|
get authority() {
|
|
354
|
-
const
|
|
389
|
+
const h = this._materialize();
|
|
390
|
+
const auth = h[':authority'];
|
|
355
391
|
if (auth !== undefined) {
|
|
356
392
|
return auth;
|
|
357
393
|
}
|
|
358
|
-
const 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.
|
|
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.
|
|
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.
|
|
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
|
|
924
|
-
|
|
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
|
|
927
|
-
stream._requestHeaders = headers;
|
|
963
|
+
const request = new Http2ServerRequest(stream);
|
|
928
964
|
const response = new Http2ServerResponse(stream);
|
|
929
965
|
|
|
930
|
-
const 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
|
-
|
|
940
|
-
|
|
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/server.js
CHANGED
|
@@ -127,6 +127,17 @@ function initHttp2Server(server, options) {
|
|
|
127
127
|
};
|
|
128
128
|
server._sessions = new Set();
|
|
129
129
|
server[kCompat] = null;
|
|
130
|
+
// node arms its compat layer through a newListener hook (setupCompat,
|
|
131
|
+
// internal/http2/core.js) rather than by wrapping the registration methods, so
|
|
132
|
+
// on()/once()/addListener() all count. The same hook arms the 'stream' bridge,
|
|
133
|
+
// which the direct compat delivery below depends on knowing about.
|
|
134
|
+
server.on('newListener', (event) => {
|
|
135
|
+
if (event === 'request') {
|
|
136
|
+
server._setupCompat();
|
|
137
|
+
} else if (event === 'stream') {
|
|
138
|
+
server._setupStreamBridge();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
130
141
|
// node validates this as uint32 and defaults it to 10000 (initializeOptions, core.js);
|
|
131
142
|
// it bounds how long an unknown-protocol socket may sit after the 403 text.
|
|
132
143
|
if (opts.unknownProtocolTimeout !== undefined &&
|
|
@@ -169,8 +180,25 @@ function attachSession(server, socket) {
|
|
|
169
180
|
}
|
|
170
181
|
});
|
|
171
182
|
}
|
|
172
|
-
session
|
|
173
|
-
|
|
183
|
+
// The session->server bridge for the application's 'stream' listeners, and the
|
|
184
|
+
// compat delivery decision. Two shapes, exactly one per session: with 'stream'
|
|
185
|
+
// listeners the session emits the built object and compat rides the server's
|
|
186
|
+
// 'stream' event behind the bridge (the listener order node has, since node
|
|
187
|
+
// subscribes onServerStream on the server); without them the session calls the
|
|
188
|
+
// compat entry directly with the stable field list, which is what lets the
|
|
189
|
+
// request object come into being at the first req.headers read instead of at
|
|
190
|
+
// frame decode (OPTIMIZATION.md item 49).
|
|
191
|
+
if (server._streamBridgeArmed === true) {
|
|
192
|
+
session.on('stream', (stream, headers, options, rawHeaders) =>
|
|
193
|
+
server.emit('stream', stream, headers, options, rawHeaders));
|
|
194
|
+
}
|
|
195
|
+
if (server[kCompat] !== null) {
|
|
196
|
+
if (server._streamBridgeArmed === true) {
|
|
197
|
+
server._armCompatChain();
|
|
198
|
+
} else {
|
|
199
|
+
session._onStreamCompat = server[kCompat];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
174
202
|
session.on('error', (err) => {
|
|
175
203
|
if (server.listenerCount('sessionError') > 0) {
|
|
176
204
|
server.emit('sessionError', err);
|
|
@@ -188,28 +216,57 @@ function applyHttp2ServerApi(proto) {
|
|
|
188
216
|
|
|
189
217
|
// node instantiates the compat req/res only when the application asks for
|
|
190
218
|
// them: a plain createServer() with a 'stream' handler never pays for two
|
|
191
|
-
// objects per request. Adding the first 'request' listener arms it
|
|
219
|
+
// objects per request. Adding the first 'request' listener arms it, via the
|
|
220
|
+
// newListener hook node itself uses (setupCompat, internal/http2/core.js).
|
|
192
221
|
proto._setupCompat = function () {
|
|
193
222
|
if (this[kCompat] !== null) {
|
|
194
223
|
return this;
|
|
195
224
|
}
|
|
196
225
|
this[kCompat] = onServerStream.bind(this);
|
|
197
226
|
this._sessionOptions.compat = true;
|
|
227
|
+
// Both delivery shapes need the raw field list: the chain hands it out as
|
|
228
|
+
// the fourth 'stream' argument, the direct call builds from it. A session
|
|
229
|
+
// that already carries the 'stream' bridge keeps compat on the server's
|
|
230
|
+
// 'stream' event; the rest take the direct call.
|
|
198
231
|
for (const session of this._sessions) {
|
|
199
232
|
session._wantRaw = true;
|
|
200
233
|
}
|
|
201
|
-
|
|
234
|
+
if (this._streamBridgeArmed === true) {
|
|
235
|
+
this._armCompatChain();
|
|
236
|
+
} else {
|
|
237
|
+
for (const session of this._sessions) {
|
|
238
|
+
session._onStreamCompat = this[kCompat];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return this;
|
|
202
242
|
};
|
|
203
243
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
244
|
+
// The bridge for the application's own 'stream' listeners, attached to the
|
|
245
|
+
// sessions that already exist (new sessions take it at accept, see
|
|
246
|
+
// attachSession). Arming it also moves the sessions that were in direct
|
|
247
|
+
// compat delivery onto the chain, so the listener order on the server's
|
|
248
|
+
// 'stream' event is the one node has however the two registrations interleave.
|
|
249
|
+
proto._setupStreamBridge = function () {
|
|
250
|
+
if (this._streamBridgeArmed === true) {
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
this._streamBridgeArmed = true;
|
|
254
|
+
for (const session of this._sessions) {
|
|
255
|
+
session.on('stream', (stream, headers, options, rawHeaders) =>
|
|
256
|
+
this.emit('stream', stream, headers, options, rawHeaders));
|
|
257
|
+
session._onStreamCompat = null;
|
|
207
258
|
}
|
|
208
|
-
|
|
259
|
+
if (this[kCompat] !== null) {
|
|
260
|
+
this._armCompatChain();
|
|
261
|
+
}
|
|
262
|
+
return this;
|
|
209
263
|
};
|
|
210
264
|
|
|
211
|
-
proto.
|
|
212
|
-
|
|
265
|
+
proto._armCompatChain = function () {
|
|
266
|
+
if (this._compatChained !== true) {
|
|
267
|
+
this._compatChained = true;
|
|
268
|
+
proto[kTransportOn].call(this, 'stream', this[kCompat]);
|
|
269
|
+
}
|
|
213
270
|
};
|
|
214
271
|
|
|
215
272
|
proto.close = function (cb) {
|
package/lib/session.js
CHANGED
|
@@ -771,6 +771,11 @@ class Http2Session extends EventEmitter {
|
|
|
771
771
|
// Copying it is a per-request allocation, so it only happens for servers
|
|
772
772
|
// that actually listen for 'request'.
|
|
773
773
|
this._wantRaw = opts.compat === true;
|
|
774
|
+
// The compat entry point the accept path calls directly with the stable
|
|
775
|
+
// field list (server.js _setupCompat); null on a session no server owns and
|
|
776
|
+
// on a server whose application listens for 'stream' only -- the object is
|
|
777
|
+
// then built for the 'stream' emit and the event chain delivers it.
|
|
778
|
+
this._onStreamCompat = null;
|
|
774
779
|
|
|
775
780
|
// Outbound frames go to the socket as one corked writev batch. A body is queued as
|
|
776
781
|
// the buffers that already hold it -- a frame header and a view of the
|
|
@@ -2698,11 +2703,44 @@ class Http2Session extends EventEmitter {
|
|
|
2698
2703
|
return;
|
|
2699
2704
|
}
|
|
2700
2705
|
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
+
// The request object is built here only when a reader is already known: a
|
|
2707
|
+
// session 'stream' listener takes it as the event argument, and the compat
|
|
2708
|
+
// request materializes it at the first req.headers access (lib/compat.js),
|
|
2709
|
+
// so a handler that only consumes the body and routes on req.url pays no
|
|
2710
|
+
// per-request object -- the paired marginal is OPTIMIZATION.md item 49. The
|
|
2711
|
+
// build still happens eagerly under shareHeaders, whose frozen shared
|
|
2712
|
+
// objects are the point of that option.
|
|
2713
|
+
const sensitive = neverNames(fields, fcount, blockFlags);
|
|
2714
|
+
const headers = shared !== null || this.listenerCount('stream') > 0 || this._share
|
|
2715
|
+
? (shared !== null ? shared
|
|
2716
|
+
: (this._share
|
|
2717
|
+
? Object.freeze(this._toObject(fields, fcount, sensitive))
|
|
2718
|
+
: this._toObject(fields, fcount, sensitive)))
|
|
2719
|
+
: undefined;
|
|
2720
|
+
// What the stack reads without the object: :method (the HEAD checks in
|
|
2721
|
+
// lib/stream.js and the compat CONNECT check), :path (req.url) and
|
|
2722
|
+
// content-length (the promise checked below). When the object was built
|
|
2723
|
+
// these are its own property reads, exactly what the eager code did; the
|
|
2724
|
+
// one-pass scan is the lazy path's only walk, and it takes the first copy
|
|
2725
|
+
// of a repeated field, the way the single-value field lands in the object.
|
|
2726
|
+
let reqMethod;
|
|
2727
|
+
let reqPath;
|
|
2728
|
+
let promised;
|
|
2729
|
+
if (headers !== undefined) {
|
|
2730
|
+
reqMethod = headers[':method'];
|
|
2731
|
+
promised = headers['content-length'];
|
|
2732
|
+
} else {
|
|
2733
|
+
for (let i = 0; i < fcount; i += 2) {
|
|
2734
|
+
const name = fields[i];
|
|
2735
|
+
if (name === ':method') {
|
|
2736
|
+
reqMethod = fields[i + 1];
|
|
2737
|
+
} else if (name === ':path') {
|
|
2738
|
+
reqPath = fields[i + 1];
|
|
2739
|
+
} else if (name === 'content-length' && promised === undefined) {
|
|
2740
|
+
promised = fields[i + 1];
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2706
2744
|
// The one shape in which the content-length promise is already broken before a single body
|
|
2707
2745
|
// octet could have arrived: the field promises a body and the HEADERS frame ends the message.
|
|
2708
2746
|
// Refusing at the accept decision -- the same place the parse failures and the size limits are
|
|
@@ -2712,7 +2750,7 @@ class Http2Session extends EventEmitter {
|
|
|
2712
2750
|
// Letting it through to Http2Stream._remoteEnded() instead resets the stream and then hands
|
|
2713
2751
|
// the handler a destroyed one, and a handler that answers it puts a response on the wire for a
|
|
2714
2752
|
// request this side has already refused.
|
|
2715
|
-
if (end &&
|
|
2753
|
+
if (end && promised !== undefined && +promised > 0) {
|
|
2716
2754
|
this.sendRst(sid, PROTOCOL_ERROR);
|
|
2717
2755
|
// The frame that carried the refusal also carried the peer's END_STREAM, so the message is
|
|
2718
2756
|
// over: the DATA that follows it (or a second HEADERS) is the error of 5.1 and not the
|
|
@@ -2726,15 +2764,21 @@ class Http2Session extends EventEmitter {
|
|
|
2726
2764
|
return;
|
|
2727
2765
|
}
|
|
2728
2766
|
const stream = new Http2Stream(this, sid);
|
|
2729
|
-
stream.
|
|
2767
|
+
stream._reqMethod = reqMethod;
|
|
2768
|
+
stream._reqPath = reqPath;
|
|
2769
|
+
stream._reqSensitive = sensitive;
|
|
2770
|
+
// node's argument order; the field list is the session's shared decode array
|
|
2771
|
+
// or a cached one, so the raw list handed out is always a copy. In the compat
|
|
2772
|
+
// path the copy is also the stable list the lazy request object builds from
|
|
2773
|
+
// (the scratch's backing array is cleared in place by the next decode), so it
|
|
2774
|
+
// travels with the stream even when no emit will carry it.
|
|
2775
|
+
const raw = this._wantRaw ? fields.slice(0, fcount) : null;
|
|
2776
|
+
stream._reqFields = raw;
|
|
2777
|
+
if (headers !== undefined) {
|
|
2778
|
+
stream._requestHeaders = headers;
|
|
2779
|
+
}
|
|
2730
2780
|
this._streams.set(sid, stream);
|
|
2731
2781
|
this._liveStreams++;
|
|
2732
|
-
// content-length is a promise about the body, and the two checks that hold the peer to it
|
|
2733
|
-
// (see _onDataFrame and Http2Stream._remoteEnded) need it as a number. The inbound
|
|
2734
|
-
// validator has already proved the value is all digits, so this is a property read and a
|
|
2735
|
-
// coercion -- and -1, the "nothing was promised" marker, costs one comparison per DATA
|
|
2736
|
-
// frame for the requests that never sent the field at all.
|
|
2737
|
-
const promised = headers['content-length'];
|
|
2738
2782
|
if (promised !== undefined) {
|
|
2739
2783
|
stream._expLen = +promised;
|
|
2740
2784
|
}
|
|
@@ -2744,10 +2788,15 @@ class Http2Session extends EventEmitter {
|
|
|
2744
2788
|
if (end) {
|
|
2745
2789
|
stream._remoteEnded();
|
|
2746
2790
|
}
|
|
2747
|
-
//
|
|
2748
|
-
//
|
|
2749
|
-
|
|
2750
|
-
|
|
2791
|
+
// Delivery turns on who is listening, not on whether an object was built:
|
|
2792
|
+
// with shareHeaders on the object exists even when no 'stream' listener
|
|
2793
|
+
// does, and emitting it into a listenerless session would drop the request
|
|
2794
|
+
// the compat callback was meant to receive.
|
|
2795
|
+
if (this.listenerCount('stream') > 0) {
|
|
2796
|
+
this.emit('stream', stream, headers, end ? OPT_END_STREAM : OPT_NO_END_STREAM, raw);
|
|
2797
|
+
} else if (this._onStreamCompat !== null) {
|
|
2798
|
+
this._onStreamCompat(stream);
|
|
2799
|
+
}
|
|
2751
2800
|
}
|
|
2752
2801
|
|
|
2753
2802
|
// node's toHeaderObject semantics: null prototype, :status coerced to a
|
package/lib/stream.js
CHANGED
|
@@ -405,8 +405,21 @@ class Http2Stream extends Stream {
|
|
|
405
405
|
this._sentStatus = 0;
|
|
406
406
|
this._sentDate = undefined;
|
|
407
407
|
this._sentView = undefined;
|
|
408
|
-
|
|
408
|
+
// sentInfoHeaders stays unset until the first informational block: node's
|
|
409
|
+
// kInfoHeaders is created by the first additionalHeaders() call
|
|
410
|
+
// (internal/http2/core.js:3285) and the getter reads undefined before it.
|
|
409
411
|
this.sentTrailers = undefined;
|
|
412
|
+
// The inbound request, as the session's accept path scanned it off the
|
|
413
|
+
// field list in one pass (lib/session.js): the :method the HEAD checks
|
|
414
|
+
// here and the compat CONNECT check read, :path for req.url, and the
|
|
415
|
+
// stable list the compat request object builds from at the first read
|
|
416
|
+
// (OPTIMIZATION.md item 49). _reqFields is null when no compat server
|
|
417
|
+
// owns the session and no raw list was asked for; _requestHeaders above
|
|
418
|
+
// stays unset until the object exists.
|
|
419
|
+
this._reqFields = null;
|
|
420
|
+
this._reqMethod = undefined;
|
|
421
|
+
this._reqPath = undefined;
|
|
422
|
+
this._reqSensitive = undefined;
|
|
410
423
|
this.headersSent = false;
|
|
411
424
|
this.pending = true;
|
|
412
425
|
this.aborted = false;
|
|
@@ -670,7 +683,7 @@ class Http2Stream extends Stream {
|
|
|
670
683
|
// request line. Same fact in h2lean, read where respond() tests it already: the flag
|
|
671
684
|
// source is the request map, so there is no state to keep out of sync.
|
|
672
685
|
get headRequest() {
|
|
673
|
-
return this.
|
|
686
|
+
return this._reqMethod === 'HEAD';
|
|
674
687
|
}
|
|
675
688
|
|
|
676
689
|
respond(headers, options) {
|
|
@@ -699,7 +712,7 @@ class Http2Stream extends Stream {
|
|
|
699
712
|
// HEADERS. Measured on the wire against live node: node puts
|
|
700
713
|
// HEADERS/ES/EH and no DATA for both shapes; h2lean used to leave a regular
|
|
701
714
|
// HEAD answer open and send the body, which nghttp2 reads as a protocol error.
|
|
702
|
-
const head = this.
|
|
715
|
+
const head = this._reqMethod === 'HEAD';
|
|
703
716
|
// node puts a `date` on every response of this API too: prepareResponseHeadersObject()
|
|
704
717
|
// (internal/http2/core.js:2702) adds one unless the application set one itself or
|
|
705
718
|
// `options.sendDate` says otherwise -- and its test is `sendDate == null || sendDate`,
|
|
@@ -781,8 +794,7 @@ class Http2Stream extends Stream {
|
|
|
781
794
|
this.ownsFd = false;
|
|
782
795
|
const sendDate = opts.sendDate == null ? true : !!opts.sendDate;
|
|
783
796
|
const { headers: prepared, statusCode } = prepareResponseHeadersObject(headers);
|
|
784
|
-
const head =
|
|
785
|
-
this._requestHeaders !== undefined && this._requestHeaders[':method'] === 'HEAD';
|
|
797
|
+
const head = this._reqMethod === 'HEAD';
|
|
786
798
|
if (statusCode === 204 || statusCode === 205 || statusCode === 304 || head) {
|
|
787
799
|
throw errorOf('ERR_HTTP2_PAYLOAD_FORBIDDEN',
|
|
788
800
|
`Responses with ${statusCode} status must not have a payload`);
|
|
@@ -834,8 +846,7 @@ class Http2Stream extends Stream {
|
|
|
834
846
|
const sendDate = opts.sendDate == null ? true : !!opts.sendDate;
|
|
835
847
|
const { headers: prepared, statusCode, isArray } =
|
|
836
848
|
prepareResponseHeadersObject(headers);
|
|
837
|
-
const head =
|
|
838
|
-
this._requestHeaders !== undefined && this._requestHeaders[':method'] === 'HEAD';
|
|
849
|
+
const head = this._reqMethod === 'HEAD';
|
|
839
850
|
if (statusCode === 204 || statusCode === 205 || statusCode === 304 || head) {
|
|
840
851
|
throw errorOf('ERR_HTTP2_PAYLOAD_FORBIDDEN',
|
|
841
852
|
`Responses with ${statusCode} status must not have a payload`);
|
|
@@ -1321,7 +1332,15 @@ class Http2Stream extends Stream {
|
|
|
1321
1332
|
// (101 has its own error), there is no default status and no generated date.
|
|
1322
1333
|
const block = hdr.block(headers, { info: true }, this.session);
|
|
1323
1334
|
const bound = hdr.sent.bound;
|
|
1324
|
-
|
|
1335
|
+
// node stores a null-proto copy of each informational block, created at the
|
|
1336
|
+
// first call (internal/http2/core.js:3265, 3285) -- the caller's object is
|
|
1337
|
+
// not retained, and the array does not exist before the first call.
|
|
1338
|
+
const copy = Object.assign({ __proto__: null }, headers);
|
|
1339
|
+
if (this.sentInfoHeaders === undefined) {
|
|
1340
|
+
this.sentInfoHeaders = [copy];
|
|
1341
|
+
} else {
|
|
1342
|
+
this.sentInfoHeaders.push(copy);
|
|
1343
|
+
}
|
|
1325
1344
|
this.session.sendHeaders(this.id, block, false, bound);
|
|
1326
1345
|
return this;
|
|
1327
1346
|
}
|
|
@@ -1397,17 +1416,36 @@ class Http2Stream extends Stream {
|
|
|
1397
1416
|
|
|
1398
1417
|
// Defaults from the parent request (node: core.js pushStream fills :method GET,
|
|
1399
1418
|
// :authority and :scheme from the request, :path '/'). The headers object is copied
|
|
1400
|
-
// into a null-proto map so the application's object is not mutated.
|
|
1401
|
-
|
|
1419
|
+
// into a null-proto map so the application's object is not mutated. The parent's
|
|
1420
|
+
// values come off the request object when it exists and off the stable field list
|
|
1421
|
+
// otherwise -- the compat request object may not have been built at all
|
|
1422
|
+
// (OPTIMIZATION.md item 49), and a pseudo-header cannot repeat, so a first match
|
|
1423
|
+
// on the list is the value the object would carry.
|
|
1402
1424
|
const h = Object.assign(Object.create(null), headers);
|
|
1403
1425
|
if (h[':method'] === undefined) {
|
|
1404
1426
|
h[':method'] = 'GET';
|
|
1405
1427
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1428
|
+
let parentAuthority;
|
|
1429
|
+
let parentScheme;
|
|
1430
|
+
const src = this._requestHeaders;
|
|
1431
|
+
if (src !== undefined) {
|
|
1432
|
+
parentAuthority = src[':authority'];
|
|
1433
|
+
parentScheme = src[':scheme'];
|
|
1434
|
+
} else {
|
|
1435
|
+
const fields = this._reqFields;
|
|
1436
|
+
for (let i = 0; i < fields.length; i += 2) {
|
|
1437
|
+
if (fields[i] === ':authority') {
|
|
1438
|
+
parentAuthority = fields[i + 1];
|
|
1439
|
+
} else if (fields[i] === ':scheme') {
|
|
1440
|
+
parentScheme = fields[i + 1];
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
if (h[':authority'] === undefined && parentAuthority !== undefined) {
|
|
1445
|
+
h[':authority'] = parentAuthority;
|
|
1408
1446
|
}
|
|
1409
|
-
if (h[':scheme'] === undefined &&
|
|
1410
|
-
h[':scheme'] =
|
|
1447
|
+
if (h[':scheme'] === undefined && parentScheme !== undefined) {
|
|
1448
|
+
h[':scheme'] = parentScheme;
|
|
1411
1449
|
}
|
|
1412
1450
|
if (h[':path'] === undefined) {
|
|
1413
1451
|
h[':path'] = '/';
|
|
@@ -1448,6 +1486,7 @@ class Http2Stream extends Stream {
|
|
|
1448
1486
|
// the getter above hands it back unchanged.
|
|
1449
1487
|
stream._sentView = h;
|
|
1450
1488
|
stream._requestHeaders = h;
|
|
1489
|
+
stream._reqMethod = h[':method'];
|
|
1451
1490
|
this.session._streams.set(promisedId, stream);
|
|
1452
1491
|
this.session._liveStreams++;
|
|
1453
1492
|
stream._remoteEnded();
|
package/package.json
CHANGED