h2lean 0.19.9 → 0.19.14

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.
@@ -135,13 +135,20 @@ class Http2ServerStream extends Http2Stream {
135
135
  this.aborted = false;
136
136
  this.endAfterHeaders = false;
137
137
  this.allowHalfOpen = false;
138
+ // node seeds this from the initialWindowSize in effect when the stream opens: the C++
139
+ // default of 65535 until our SETTINGS is acked, the advertised value afterwards
140
+ // (measured on v26.12.1 with initialWindowSize 18: HEADERS before the ACK reports
141
+ // 65535, one after reports 18). A stream therefore keeps the window it was born with
142
+ // even if SETTINGS changes later, which is why the credit math uses this same value.
143
+ this._streamInitialWindow = session._settingsAcked
144
+ ? session.localSettings.initialWindowSize : 65535;
138
145
  this._state = {
139
146
  state: ST_OPEN,
140
147
  weight: 16,
141
148
  sumDependencyWeight: 0,
142
149
  localClose: 0,
143
150
  remoteClose: 0,
144
- localWindowSize: session.localSettings.initialWindowSize
151
+ localWindowSize: this._streamInitialWindow
145
152
  };
146
153
  this._sendWin = session.remoteSettings.initialWindowSize;
147
154
  this._recvUsed = 0; // inbound bytes not yet released as credit
@@ -214,6 +221,13 @@ class Http2ServerStream extends Http2Stream {
214
221
  get destroyed() {
215
222
  return this._destroyed;
216
223
  }
224
+ // node's stream exposes these as writable fields (Duplex's data properties;
225
+ // `destroyed` writes _destroyed). The compat socket proxy forwards an
226
+ // assignment to them. Prototype-only accessors keep the per-request shape
227
+ // unchanged; the override fields exist only after an assignment.
228
+ set destroyed(value) {
229
+ this._destroyed = value;
230
+ }
217
231
 
218
232
  get closed() {
219
233
  // node's STREAM_FLAGS_CLOSED (core.js:2458) -- set by close() at entry, so the
@@ -238,8 +252,15 @@ class Http2ServerStream extends Http2Stream {
238
252
  }
239
253
 
240
254
  get readable() {
255
+ if (this._readableOverridden === true) {
256
+ return this._readableOverride;
257
+ }
241
258
  return !this._destroyed && this._errorEmitted !== true && this._eofEmitted !== true;
242
259
  }
260
+ set readable(value) {
261
+ this._readableOverridden = true;
262
+ this._readableOverride = value;
263
+ }
243
264
 
244
265
  get readableEnded() {
245
266
  return this._eofEmitted === true;
@@ -284,8 +305,15 @@ class Http2ServerStream extends Http2Stream {
284
305
  }
285
306
 
286
307
  get writable() {
308
+ if (this._writableOverridden === true) {
309
+ return this._writableOverride;
310
+ }
287
311
  return !this._destroyed && !this._ending && this._streamErrored === undefined;
288
312
  }
313
+ set writable(value) {
314
+ this._writableOverridden = true;
315
+ this._writableOverride = value;
316
+ }
289
317
 
290
318
  get writableEnded() {
291
319
  return this._ending || (this._destroyed && this._streamErrored === undefined);
@@ -728,12 +756,14 @@ class Http2ServerStream extends Http2Stream {
728
756
  // node's Writable.end flips _writableState.ending here, before anything is sent
729
757
  // -- even when the body is still parked on window credit. 'aborted' reads it.
730
758
  this._ending = true;
731
- if (!this.headersSent) {
759
+ if (!this.headersSent && !this._closing) {
732
760
  // A body takes the auto-respond of write() above; an empty end() is where h2lean and node
733
761
  // part company, and the split is written down in AGENTS.md section 10: node puts NOTHING on
734
762
  // the wire for `end()` before respond() -- no HEADERS, no DATA, no END_STREAM, and
735
763
  // headersSent stays false -- while h2lean answers a plain 200 rather than leave a stream
736
- // that no peer will ever see an answer on.
764
+ // that no peer will ever see an answer on. close() ends the writable side too, but node's
765
+ // closeStream does not start a response there, so the flag close() sets at entry keeps
766
+ // this h2lean-only answer out of the teardown.
737
767
  this.respond({ ':status': 200 });
738
768
  }
739
769
  if (this._state.localClose === 1) {
@@ -744,6 +774,19 @@ class Http2ServerStream extends Http2Stream {
744
774
  }
745
775
  return this;
746
776
  }
777
+ if (this._closing && !this.headersSent) {
778
+ // A stream close ends the writable side of an unresponded stream without
779
+ // staging anything: node's shutdownWritable has no HEADERS and no DATA to
780
+ // submit there, and a DATA/ES on an unopened stream is a protocol error
781
+ // for the peer. The RST_STREAM close() submits is the only wire work;
782
+ // close()'s _destroy records the local half after this returns. The
783
+ // writable 'finish' is still owed before that teardown, as on node.
784
+ this._scheduleFinish();
785
+ if (cb) {
786
+ this._tick(cb);
787
+ }
788
+ return this;
789
+ }
747
790
  const buf = chunk == null ? EMPTY : (typeof chunk === 'string'
748
791
  ? Buffer.from(chunk, encoding || 'utf8') : chunk);
749
792
  // A stream that still owes a trailer block must not close the stream with its body.
@@ -893,18 +936,19 @@ class Http2ServerStream extends Http2Stream {
893
936
  // closeStream (core.js:2071-2101) is the base method both sides share. It sets
894
937
  // STREAM_FLAGS_CLOSED and rstCode at ENTRY, before the abort and the RST decision
895
938
  // -- a second close() is a no-op even while the teardown still waits on 'finish'.
896
- // h2lean sets the flag after the end() below instead: this end() is the one place
897
- // the auto-respond runs, and respond() refuses a closed stream -- setting the flag
898
- // first would throw out of close() on the unresponded shape node's plain end()
899
- // never reaches (AGENTS.md section 10).
939
+ // The end() below still ends the writable side, but its h2lean-only auto-respond
940
+ // is suppressed through _closing: respond() refuses a closed stream, so the
941
+ // marker cannot be deferred past that call the way it used to be.
942
+ this._closedFlag = true;
943
+ this.rstCode = code;
900
944
  const ending = this._ending;
901
945
  if (!ending) {
902
946
  this.aborted = true;
903
947
  this.emit('aborted');
948
+ this._closing = true;
904
949
  this.end();
950
+ this._closing = false;
905
951
  }
906
- this._closedFlag = true;
907
- this.rstCode = code;
908
952
  if (ending && this._writableFinished !== true && code === NO_ERROR) {
909
953
  this.once('finish', () => this._destroy(code, true));
910
954
  } else {
@@ -927,6 +971,14 @@ class Http2ServerStream extends Http2Stream {
927
971
  if (this._destroyed || this.closed) {
928
972
  throw errorOf('ERR_HTTP2_INVALID_STREAM', 'The stream has been destroyed');
929
973
  }
974
+ // node checks headersSent immediately after the liveness rule
975
+ // (internal/http2/core.js:3260, v26.12.1): a call after respond() throws
976
+ // ERR_HTTP2_HEADERS_AFTER_RESPOND before validation or framing, so no extra
977
+ // HEADERS reaches the peer (message from internal/errors.js:1271).
978
+ if (this.headersSent) {
979
+ throw errorOf('ERR_HTTP2_HEADERS_AFTER_RESPOND',
980
+ 'Cannot specify additional headers after response initiated');
981
+ }
930
982
  // `{ info: true }` is node's separate rule for these blocks: :status must be 100..199
931
983
  // (101 has its own error), there is no default status and no generated date.
932
984
  // prepare() performs that validation before the copy is made, and the plan it
@@ -47,7 +47,7 @@
47
47
 
48
48
  const { Readable, Stream } = require('node:stream');
49
49
 
50
- const { nullProto, trimName, isFieldName } = require('../headers');
50
+ const { nullProto, trimName } = require('../headers');
51
51
  const { kCompatSocket } = require('../Http2Stream');
52
52
  const { NO_ERROR } = require('../frames');
53
53
  const { Http2ServerStream } = require('./Http2ServerStream');
@@ -77,8 +77,28 @@ Http2ServerStream.prototype._destroy = function compatTrackedDestroy(code, sendR
77
77
  // step without an extra require on the session's hot path.
78
78
  const kCompatRawTrailers = Symbol.for('h2lean.compat.rawTrailers');
79
79
 
80
+ // node declares its validation errors with a class (internal/errors.js):
81
+ // header and argument validation is TypeError, status codes are RangeError,
82
+ // stream-state errors stay plain Error. ERR_HTTP2_HEADERS_SENT stays an Error
83
+ // here too -- h2lean's message differs from node's and that is written down,
84
+ // while the class the application catches is the same.
85
+ const TYPE_ERROR_CODES = new Set([
86
+ 'ERR_INVALID_ARG_TYPE',
87
+ 'ERR_INVALID_ARG_VALUE',
88
+ 'ERR_INVALID_HTTP_TOKEN',
89
+ 'ERR_HTTP2_INVALID_HEADER_VALUE',
90
+ 'ERR_HTTP2_INVALID_PSEUDOHEADER',
91
+ 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'
92
+ ]);
93
+ const RANGE_ERROR_CODES = new Set([
94
+ 'ERR_HTTP2_STATUS_INVALID',
95
+ 'ERR_HTTP2_INFO_STATUS_NOT_ALLOWED',
96
+ 'ERR_HTTP2_INVALID_INFO_STATUS'
97
+ ]);
80
98
  function err(code, msg) {
81
- const e = new Error(msg);
99
+ const Ctor = RANGE_ERROR_CODES.has(code) ? RangeError
100
+ : TYPE_ERROR_CODES.has(code) ? TypeError : Error;
101
+ const e = new Ctor(msg);
82
102
  e.code = code;
83
103
  return e;
84
104
  }
@@ -238,6 +258,69 @@ function checkName(name) {
238
258
  }
239
259
  }
240
260
 
261
+ // node's compat layer warns once per process for a status message, whether it
262
+ // was read, written or passed to writeHead (internal/http2/compat.js:75,112).
263
+ // The warning is an UnsupportedWarning with node's exact text; the round trip
264
+ // and the wire bytes are unaffected.
265
+ let statusMessageWarned = false;
266
+ function statusMessageWarn() {
267
+ if (!statusMessageWarned) {
268
+ process.emitWarning(
269
+ 'Status message is not supported by HTTP/2 (RFC7540 8.1.2.4)',
270
+ 'UnsupportedWarning');
271
+ statusMessageWarned = true;
272
+ }
273
+ }
274
+
275
+ // node's one header check for every name/value accessor (internal/http2/compat.js:82).
276
+ // The five defined pseudo headers are refused here; an unknown ':' name is
277
+ // refused downstream by assertValidPseudoHeader as ERR_HTTP2_INVALID_PSEUDOHEADER.
278
+ // A token check is deliberately not added here: node's setHeader destroys the
279
+ // stream for a bad token rather than throwing, which is a different path.
280
+ const PSEUDO_HEADERS = new Set([':status', ':method', ':path', ':authority', ':scheme']);
281
+ function assertValidHeader(name, value) {
282
+ if (typeof name !== 'string' || name === '' || name.includes(' ')) {
283
+ throw err('ERR_INVALID_HTTP_TOKEN', `Header name must be a valid HTTP token ["${name}"]`);
284
+ }
285
+ if (PSEUDO_HEADERS.has(name)) {
286
+ throw err('ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED', 'Cannot set HTTP/2 pseudo-headers');
287
+ }
288
+ if (name.charCodeAt(0) === 58) { // ':'
289
+ throw err('ERR_HTTP2_INVALID_PSEUDOHEADER',
290
+ `"${name}" is an invalid pseudoheader or is used incorrectly`);
291
+ }
292
+ if (value === undefined || value === null) {
293
+ throw err('ERR_HTTP2_INVALID_HEADER_VALUE', `Invalid value "${value}" for header "${name}"`);
294
+ }
295
+ }
296
+
297
+ // node's own token grammar (_http_common.js:216), not headers.js's isFieldName:
298
+ // that one writes to the bounded process-wide VALID_NAMES cache on every new
299
+ // name, which a per-header compat path must not grow.
300
+ const HTTP_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
301
+
302
+ // h2lean's timer is on the session, so arming both the request and the response
303
+ // leaves two once('timeout') wrappers on it; one emission calls both. node
304
+ // re-emits 'timeout' once on each compat object, so the first wrapper emits
305
+ // both events and the later ones run their callback only. The flag lives on
306
+ // the stream and is cleared in the next tick, the turn of one emission.
307
+ function clearCompatTimeoutEmitted(stream) {
308
+ stream._compatTimeoutEmitted = false;
309
+ }
310
+ function emitCompatTimeout(stream, req, res) {
311
+ if (stream._compatTimeoutEmitted === true) {
312
+ return;
313
+ }
314
+ stream._compatTimeoutEmitted = true;
315
+ stream._tick(clearCompatTimeoutEmitted, stream);
316
+ if (req !== undefined) {
317
+ req.emit('timeout');
318
+ }
319
+ if (res !== undefined) {
320
+ res.emit('timeout');
321
+ }
322
+ }
323
+
241
324
  // node's wording for a value of the wrong type (internal/errors.js,
242
325
  // determineSpecificType): the message is what an application reads when it
243
326
  // catches the error, so it says what node says.
@@ -253,6 +336,15 @@ function describeType(value) {
253
336
  if (value === 0) {
254
337
  return 1 / value === -Infinity ? 'type number (-0)' : 'type number (0)';
255
338
  }
339
+ if (Number.isNaN(value)) {
340
+ return 'type number (NaN)';
341
+ }
342
+ if (value === Infinity) {
343
+ return 'type number (Infinity)';
344
+ }
345
+ if (value === -Infinity) {
346
+ return 'type number (-Infinity)';
347
+ }
256
348
  return `type number (${value})`;
257
349
  case 'bigint': return `type bigint (${value}n)`;
258
350
  case 'boolean': return `type boolean (${value})`;
@@ -262,6 +354,12 @@ function describeType(value) {
262
354
  const name = value.constructor?.name;
263
355
  return typeof name === 'string' && name !== '' ? `an instance of ${name}` : 'an instance of Object';
264
356
  }
357
+ case 'string': {
358
+ // determineSpecificType truncates long strings and quotes with the
359
+ // delimiter that does not occur in the value (internal/errors.js:1048).
360
+ const str = value.length > 28 ? `${value.slice(0, 25)}...` : value;
361
+ return str.includes("'") ? `type string (${JSON.stringify(str)})` : `type string ('${str}')`;
362
+ }
265
363
  default: return `type ${typeof value}`;
266
364
  }
267
365
  }
@@ -608,12 +706,10 @@ class Http2ServerRequest extends Readable {
608
706
  // setTimeout call, only on the opt-in path; the timer path itself is
609
707
  // unchanged.
610
708
  const req = this;
611
- const res = this._stream._response;
612
- this._stream.setTimeout(msecs, function onCompatTimeout() {
613
- req.emit('timeout');
614
- if (res !== undefined) {
615
- res.emit('timeout');
616
- }
709
+ const stream = this._stream;
710
+ const res = stream._response;
711
+ stream.setTimeout(msecs, function onCompatTimeout() {
712
+ emitCompatTimeout(stream, req, res);
617
713
  if (callback !== undefined) {
618
714
  callback.apply(this, arguments);
619
715
  }
@@ -789,21 +885,21 @@ class Http2ServerResponse extends Stream {
789
885
  set statusCode(code) {
790
886
  code |= 0;
791
887
  if (code >= 100 && code < 200) {
792
- throw err('ERR_HTTP2_INFO_STATUS_NOT_ALLOWED', 'informational status codes cannot be set on statusCode');
888
+ throw err('ERR_HTTP2_INFO_STATUS_NOT_ALLOWED', 'Informational status codes cannot be used');
793
889
  }
794
890
  if (code < 100 || code > 599) {
795
- throw err('ERR_HTTP2_STATUS_INVALID', `invalid status code: ${code}`);
891
+ throw err('ERR_HTTP2_STATUS_INVALID', `Invalid status code: ${code}`);
796
892
  }
797
893
  this._state.statusCode = code;
798
894
  }
799
895
 
800
- // HTTP/2 has no reason phrase; node warns and returns ''.
896
+ // HTTP/2 has no reason phrase; node warns once and returns ''.
801
897
  get statusMessage() {
802
- process.emitWarning('HTTP/2 does not support a status message', 'Warning');
898
+ statusMessageWarn();
803
899
  return '';
804
900
  }
805
901
  set statusMessage(msg) {
806
- process.emitWarning('HTTP/2 does not support a status message', 'Warning');
902
+ statusMessageWarn();
807
903
  }
808
904
 
809
905
  get sendDate() {
@@ -860,7 +956,9 @@ class Http2ServerResponse extends Stream {
860
956
  // validate the name either (internal/http2/compat.js), so a name that is not
861
957
  // a string fails here the way it fails there: name.trim() is not a function.
862
958
  _setHeader(name, value) {
863
- this._headers[trimName(name)] = value;
959
+ const key = trimName(name);
960
+ assertValidHeader(key, value);
961
+ this._headers[key] = value;
864
962
  }
865
963
 
866
964
  appendHeader(name, value) {
@@ -869,6 +967,7 @@ class Http2ServerResponse extends Stream {
869
967
  throw err('ERR_HTTP2_HEADERS_SENT', 'response has already been sent');
870
968
  }
871
969
  const key = trimName(name);
970
+ assertValidHeader(key, value);
872
971
  const current = this._headers[key];
873
972
  if (current === undefined) {
874
973
  this._headers[key] = value;
@@ -887,10 +986,12 @@ class Http2ServerResponse extends Stream {
887
986
  // fast path must recall its frame so the same shape holds here (item 44); after
888
987
  // the flush the frame is gone and the trailer is lost on node too, its tick
889
988
  // having already answered the empty block.
989
+ const key = trimName(name);
990
+ assertValidHeader(key, value);
890
991
  if (this._stream._esStaged) {
891
992
  this._stream._recallStagedEnd();
892
993
  }
893
- this._trailers[trimName(name)] = value;
994
+ this._trailers[key] = value;
894
995
  }
895
996
 
896
997
  addTrailers(headers) {
@@ -908,23 +1009,33 @@ class Http2ServerResponse extends Stream {
908
1009
  throw err('ERR_HTTP2_HEADERS_SENT', 'response has already been sent');
909
1010
  }
910
1011
  if (typeof statusMessage === 'string') {
911
- process.emitWarning('HTTP/2 does not support a status message', 'Warning');
1012
+ statusMessageWarn();
912
1013
  }
913
1014
  if (headers === undefined && typeof statusMessage === 'object') {
914
1015
  headers = statusMessage;
915
1016
  }
916
1017
 
917
1018
  if (Array.isArray(headers)) {
1019
+ // node removes every incoming name first, then appends each pair, so a
1020
+ // repeated name in the array is two field lines on the wire rather than
1021
+ // one overwritten value (internal/http2/compat.js:735-770). The object
1022
+ // branch below still replaces through _setHeader().
918
1023
  if (headers.length && Array.isArray(headers[0])) {
919
1024
  for (let i = 0; i < headers.length; i++) {
920
- this._setHeader(headers[i][0], headers[i][1]);
1025
+ this.removeHeader(headers[i][0]);
1026
+ }
1027
+ for (let i = 0; i < headers.length; i++) {
1028
+ this.appendHeader(headers[i][0], headers[i][1]);
921
1029
  }
922
1030
  } else {
923
1031
  if (headers.length % 2 !== 0) {
924
1032
  throw err('ERR_INVALID_ARG_VALUE', 'headers array must be flat key/value pairs');
925
1033
  }
926
1034
  for (let i = 0; i < headers.length; i += 2) {
927
- this._setHeader(headers[i], headers[i + 1]);
1035
+ this.removeHeader(headers[i]);
1036
+ }
1037
+ for (let i = 0; i < headers.length; i += 2) {
1038
+ this.appendHeader(headers[i], headers[i + 1]);
928
1039
  }
929
1040
  }
930
1041
  } else if (typeof headers === 'object' && headers !== null) {
@@ -991,7 +1102,7 @@ class Http2ServerResponse extends Stream {
991
1102
  // means "switch protocol", which HTTP/2 forbids outright (RFC 9113 8.5).
992
1103
  if (typeof statusCode !== 'number' || statusCode < 100 || statusCode > 199
993
1104
  || statusCode === 101) {
994
- throw err('ERR_HTTP2_STATUS_INVALID', `invalid informational status code: ${statusCode}`);
1105
+ throw err('ERR_HTTP2_STATUS_INVALID', `Invalid status code: ${statusCode}`);
995
1106
  }
996
1107
  if (this._stream.headersSent || this._state.closed) {
997
1108
  return false;
@@ -1033,18 +1144,11 @@ class Http2ServerResponse extends Stream {
1033
1144
  continue;
1034
1145
  }
1035
1146
  const name = key.trim().toLowerCase();
1036
- if (name === '' || name.includes(' ')) {
1037
- throw err('ERR_INVALID_HTTP_TOKEN', `Header name must be a valid HTTP token ["${name}"]`);
1038
- }
1039
- if (name.charCodeAt(0) === 58) { // ':'
1040
- throw err('ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED', 'Cannot set HTTP/2 pseudo-headers');
1041
- }
1042
1147
  const value = hints[key];
1043
- if (value === undefined || value === null) {
1044
- throw err('ERR_HTTP2_INVALID_HEADER_VALUE',
1045
- `Invalid value "${value}" for header "${name}"`);
1046
- }
1047
- if (!isFieldName(name)) {
1148
+ assertValidHeader(name, value);
1149
+ // writeEarlyHints is the one compat path that throws on a bad token
1150
+ // instead of destroying the stream (internal/http2/compat.js:955).
1151
+ if (!HTTP_TOKEN.test(name)) {
1048
1152
  throw err('ERR_INVALID_HTTP_TOKEN', `Header name must be a valid HTTP token ["${name}"]`);
1049
1153
  }
1050
1154
  headers[name] = value;
@@ -1202,7 +1306,19 @@ class Http2ServerResponse extends Stream {
1202
1306
  if (this._state.closed || this._stream.destroyed) {
1203
1307
  return this;
1204
1308
  }
1205
- this._stream.setTimeout(msecs, callback);
1309
+ // node attaches the callback as a 'timeout' listener on the stream, and
1310
+ // the compat response re-emits the stream event as its own 'timeout'
1311
+ // (internal/http2/compat.js:435,878). Mirror both here; the shared helper
1312
+ // keeps the single event when the request armed the same timer.
1313
+ const res = this;
1314
+ const stream = this._stream;
1315
+ const req = this.req;
1316
+ stream.setTimeout(msecs, function onCompatResponseTimeout() {
1317
+ emitCompatTimeout(stream, req, res);
1318
+ if (callback !== undefined) {
1319
+ callback.apply(this, arguments);
1320
+ }
1321
+ });
1206
1322
  return this;
1207
1323
  }
1208
1324
 
@@ -1225,7 +1341,13 @@ class Http2ServerResponse extends Stream {
1225
1341
  callback(e);
1226
1342
  return;
1227
1343
  }
1228
- const push = new Http2ServerResponse(stream);
1344
+ // node's compat creates a pushed response with the same constructor the server
1345
+ // was given via Http2ServerResponse (internal/http2/compat, createPushResponse).
1346
+ const server = this._stream.session !== undefined
1347
+ ? this._stream.session.server : undefined;
1348
+ const Response = server !== undefined && server._http2ServerResponse !== undefined
1349
+ ? server._http2ServerResponse : Http2ServerResponse;
1350
+ const push = new Response(stream);
1229
1351
  // A pushed stream has no request, so nothing else installs the compat
1230
1352
  // dispatch on it; the response's handlers need it the same way the
1231
1353
  // request's constructor installs it for a normal exchange.
@@ -1241,8 +1363,16 @@ class Http2ServerResponse extends Stream {
1241
1363
  // the server as `this`.
1242
1364
  function onServerStream(stream) {
1243
1365
  const server = this;
1244
- const request = new Http2ServerRequest(stream);
1245
- const response = new Http2ServerResponse(stream);
1366
+ // node's setupCompat hands the server's Http2ServerRequest/Http2ServerResponse
1367
+ // options to the compat layer, so the handler receives the caller's subclasses.
1368
+ // The objects are still built here, at the first compat delivery, with the same
1369
+ // lazy-instantiation and dispatch-before-event order as before.
1370
+ const Request = server._http2ServerRequest !== undefined
1371
+ ? server._http2ServerRequest : Http2ServerRequest;
1372
+ const Response = server._http2ServerResponse !== undefined
1373
+ ? server._http2ServerResponse : Http2ServerResponse;
1374
+ const request = new Request(stream);
1375
+ const response = new Response(stream);
1246
1376
 
1247
1377
  const method = stream._reqMethod;
1248
1378
  if (method === 'CONNECT') {