http2-express 1.1.0 → 1.1.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.
package/README.md CHANGED
@@ -1,12 +1,27 @@
1
1
  # http2-express
2
2
  This package adds HTTP/2 support to express.js applications.
3
3
 
4
+ **Version 1.1.1** Fixes the following bugs:
5
+ 1. Fixed the crash issue when a stream is already destroyed.
6
+ 2. Removed the side-effecting hostname getter that mutated this.headers['host']. The host header is now initialized once, upfront, in middleware.
7
+ 3. Wrapped Object.setPrototypeOf calls in try/catch so errors go to next(err) instead of hanging the request.
8
+ 4. Express5 detection now uses parseInt(express.version, 10) >= 5 with the old heuristic as fallback. No longer breaks if lazyrouter is monkey-patched.
9
+ 5. Removed response.push = () => {} which mutated the shared Express prototype; push no-ops are now set only on app._response and app.http2Response.
10
+ 6. Added headers['host'] initialization in the Express 5 router middleware.
11
+ 7. If Express is not installed in your project, or your installed Express version is below version 4.0.0, you'll get a warning.
12
+ <br>
13
+ <br>
14
+
4
15
  **Version 1.1.0** adds support for **EXPRESS 5**. [grainrigi](https://github.com/grainrigi) was able to make the changes necessary to support **EXPRESS 5**.
5
16
  This version is also backward compatible with Express 4.
6
-
7
- **NOTICE**: This package is fully compatible with the old [http2-express-bridge](https://www.npmjs.com/package/http2-express-bridge). You should be able to replace the old package [http2-express-bridge](https://www.npmjs.com/package/http2-express-bridge) with this new one ("**http2-express**") without changing anything in your code, except the package name in the import (see usage below).
17
+ <br>
18
+ <br>
8
19
 
9
20
  **Version 1.0.1** fixes an issue with h2c (running HTTP/2 without TLS) as reported by rickardkarlsson. You should now be able to create a non https server (http2.createServer.....) without any issues.
21
+ <br>
22
+ <br>
23
+
24
+ **NOTICE**: This package is fully compatible with the old [http2-express-bridge](https://www.npmjs.com/package/http2-express-bridge). You should be able to replace the old package [http2-express-bridge](https://www.npmjs.com/package/http2-express-bridge) with this new one ("**http2-express**") without changing anything in your code, except the package name in the import (see usage below).
10
25
 
11
26
  ## Installation
12
27
  ```bash
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "http2-express",
3
+ "type": "commonjs",
4
+ "sideEffects": false,
3
5
  "description": "HTTP/2 support for Express",
4
- "version": "1.1.0",
6
+ "version": "1.1.1",
5
7
  "author": "Mark Jovis",
6
8
  "contributors": [
7
- "Mark Jovis <mark.jovis@hotmail.com>"
9
+ "grainrigi"
8
10
  ],
9
11
  "license": "MIT",
10
12
  "keywords": [
@@ -17,21 +19,18 @@
17
19
  "api",
18
20
  "server"
19
21
  ],
20
- "main": "dist/index.js",
21
- "module": "dist/index.js",
22
+ "main": "src/index.js",
23
+ "files": ["src/"],
22
24
  "scripts": {
23
- "build": "babel src -d dist",
24
- "prepublishOnly": "npm run build",
25
- "createTypeFiles": "npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --outDir types",
26
- "test": "echo \"Error: no test specified\" && exit 1"
25
+ "createTypeFiles": "npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --outDir types"
26
+ },
27
+ "peerDependencies": {
28
+ "express": ">=4.0.0"
27
29
  },
28
30
  "devDependencies": {
29
- "@babel/cli": "^7.23.9",
30
- "@babel/eslint-parser": "^7.23.10",
31
- "@babel/preset-env": "^7.23.9",
32
- "eslint": "^8.57.0",
33
- "eslint-config-airbnb-base": "^15.0.0",
34
- "eslint-plugin-import": "^2.29.1"
31
+ "@eslint/js": "^10.0.1",
32
+ "eslint": "^10.5.0",
33
+ "globals": "^17.6.0"
35
34
  },
36
35
  "engines": {
37
36
  "node": ">= 20.0.0"
package/src/core.js CHANGED
@@ -1,10 +1,10 @@
1
- /* eslint-disable func-names */
2
- /* eslint-disable no-underscore-dangle */
1
+ 'use strict';
2
+
3
3
  const EventEmitter = require('events');
4
4
 
5
- const createHttp2Request = require('./http2Request');
6
- const createHttp2Response = require('./http2Response');
7
- const initHttp2Express = require('./initHttp2Express');
5
+ const createHttp2Request = require('./http2-request');
6
+ const createHttp2Response = require('./http2-response');
7
+ const initHttp2Express = require('./init-http2-express');
8
8
  const { setPoweredBy, isHttp2Request } = require('./util');
9
9
 
10
10
  const createHttp2Express = (express) => {
@@ -16,18 +16,28 @@ const createHttp2Express = (express) => {
16
16
  query
17
17
  } = express;
18
18
 
19
- const isExpress5 = !application.lazyrouter;
19
+ // Detect Express 5 via the version string (positive-space check) with a
20
+ // fallback to the absence-of-lazyrouter heuristic for edge cases where
21
+ // express.version is unavailable.
22
+ const isExpress5 = express.version
23
+ ? parseInt(express.version, 10) >= 5
24
+ : typeof application.lazyrouter !== 'function';
20
25
 
21
26
  if (isExpress5) {
22
27
  const originalInit = application.init;
23
28
  application.init = function init() {
24
29
  originalInit.call(this);
25
- // at this point we can use the router
26
30
  this.router.use((req, res, next) => {
27
31
  setPoweredBy(this, res);
32
+ // HTTP/2 carries the host in :authority. Populate headers['host'] once,
33
+ // upfront, so Express's req.hostname getter and any header-inspection
34
+ // middleware see a consistent value from the start.
35
+ if (isHttp2Request(req) && !req.headers['host'] && req.authority) {
36
+ req.headers['host'] = req.authority;
37
+ }
28
38
  next();
29
39
  });
30
- }
40
+ };
31
41
  } else {
32
42
  application.lazyrouter = function lazyrouter() {
33
43
  if (!this._router) {
@@ -41,13 +51,20 @@ const createHttp2Express = (express) => {
41
51
  };
42
52
  }
43
53
 
54
+ // For Express 5: intercept the app.request/app.response reads that happen
55
+ // synchronously at the top of app.handle, so H2 connections get the HTTP/2
56
+ // prototype set immediately — before any stream machinery can run _read().
57
+ // This must happen at the getter level, not in a middleware, because by the
58
+ // time middleware runs the wrong prototype is already set on the request.
59
+ //
60
+ // Safe under Node.js's single-threaded event loop: the overrides are set and
61
+ // consumed within the same synchronous call stack (no await between them and
62
+ // Express 5's prototype reads inside app.handle).
44
63
  let oneshotRequestOverride = null;
45
64
  let oneshotResponseOverride = null;
46
65
 
47
66
  const app = function (req, res, next) {
48
67
  if (isExpress5 && isHttp2Request(req)) {
49
- // In Express 5, setting the prototype of req/res is done synchronously in the app.handle function,
50
- // so this is the right place to change the value of app.request/app.response.
51
68
  oneshotRequestOverride = app.http2Request;
52
69
  oneshotResponseOverride = app.http2Response;
53
70
  }
@@ -86,8 +103,6 @@ const createHttp2Express = (express) => {
86
103
  }
87
104
  });
88
105
 
89
- response.push = () => {};
90
-
91
106
  app._request = Object.create(request, {
92
107
  app: {
93
108
  configurable: true,
@@ -106,6 +121,9 @@ const createHttp2Express = (express) => {
106
121
  }
107
122
  });
108
123
 
124
+ // No-op push on the per-app HTTP/1 response object only.
125
+ app._response.push = () => { };
126
+
109
127
  const http2Request = createHttp2Request(request);
110
128
  const http2Response = createHttp2Response(response);
111
129
 
@@ -127,38 +145,35 @@ const createHttp2Express = (express) => {
127
145
  }
128
146
  });
129
147
 
130
- // Expose the prototype that will get set on requests.
148
+ // No-op push on the per-app HTTP/2 response object only.
149
+ app.http2Response.push = () => { };
150
+
131
151
  Object.defineProperty(app, 'request', {
132
152
  configurable: true,
133
153
  enumerable: true,
134
154
  get() {
135
155
  if (oneshotRequestOverride) {
136
- const req = oneshotRequestOverride;
156
+ const val = oneshotRequestOverride;
137
157
  oneshotRequestOverride = null;
138
- return req;
158
+ return val;
139
159
  }
140
160
  return app._request;
141
161
  },
142
- set: (val) => {
143
- app._request = val;
144
- }
162
+ set(val) { app._request = val; }
145
163
  });
146
164
 
147
- // Expose the prototype that will get set on responses.
148
165
  Object.defineProperty(app, 'response', {
149
166
  configurable: true,
150
167
  enumerable: true,
151
168
  get() {
152
169
  if (oneshotResponseOverride) {
153
- const res = oneshotResponseOverride;
170
+ const val = oneshotResponseOverride;
154
171
  oneshotResponseOverride = null;
155
- return res;
172
+ return val;
156
173
  }
157
174
  return app._response;
158
175
  },
159
- set: (val) => {
160
- app._response = val;
161
- }
176
+ set(val) { app._response = val; }
162
177
  });
163
178
 
164
179
  app.init();
@@ -1,4 +1,5 @@
1
- /* eslint-disable dot-notation */
1
+ 'use strict';
2
+
2
3
  const { Http2ServerRequest } = require('http2');
3
4
 
4
5
  const createHttp2Request = (request) => {
@@ -20,19 +21,10 @@ const createHttp2Request = (request) => {
20
21
  }
21
22
  });
22
23
 
23
- const requestHostName = Object.getOwnPropertyDescriptor(http2Request, 'hostname')?.get;
24
-
25
- // Redefine hostname property with custom getter.
26
- if (requestHostName) {
27
- Object.defineProperty(http2Request, 'hostname', {
28
- get() {
29
- if (!this.headers['host'] && this.authority) {
30
- this.headers['host'] = this.authority;
31
- }
32
- return requestHostName.call(this);
33
- }
34
- });
35
- }
24
+ // The hostname getter from Express reads this.headers['host'].
25
+ // HTTP/2 requests carry the host via the :authority pseudo-header instead,
26
+ // so initHttp2Express populates headers['host'] from req.authority before
27
+ // any route handlers run. No getter override needed here.
36
28
 
37
29
  return http2Request;
38
30
  };
@@ -1,3 +1,5 @@
1
+ 'use strict';
2
+
1
3
  const { Http2ServerResponse } = require('http2');
2
4
 
3
5
  const createHttp2Response = (response) => {
package/src/index.js CHANGED
@@ -1,4 +1,9 @@
1
+ 'use strict';
2
+
1
3
  const createHttp2Express = require('./core');
2
4
 
3
5
  module.exports = createHttp2Express;
4
- exports.default = createHttp2Express;
6
+ // Fix: attach .default to module.exports (not to the detached `exports` binding).
7
+ // After `module.exports = X`, the `exports` variable no longer refers to module.exports,
8
+ // so `exports.default = X` would write to an orphaned object with no effect.
9
+ module.exports.default = createHttp2Express;
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ const { isHttp2Request, setPoweredBy } = require('./util');
4
+
5
+ const initHttp2Express = (app) => (req, res, next) => {
6
+ setPoweredBy(app, res);
7
+ req.res = res;
8
+ res.req = req;
9
+ req.next = next;
10
+
11
+ try {
12
+ if (isHttp2Request(req)) {
13
+ // HTTP/2 uses :authority instead of the Host header. Populate headers['host']
14
+ // once, upfront, so that Express's req.hostname getter and any middleware
15
+ // that reads req.headers directly see a consistent value from the start.
16
+ if (!req.headers['host'] && req.authority) {
17
+ req.headers['host'] = req.authority;
18
+ }
19
+ Object.setPrototypeOf(req, app.http2Request);
20
+ Object.setPrototypeOf(res, app.http2Response);
21
+ } else {
22
+ Object.setPrototypeOf(req, app.request);
23
+ Object.setPrototypeOf(res, app.response);
24
+ }
25
+ } catch (err) {
26
+ return next(err);
27
+ }
28
+
29
+ res.locals = res.locals || Object.create(null);
30
+ next();
31
+ };
32
+
33
+ module.exports = initHttp2Express;
package/src/util.js CHANGED
@@ -1,10 +1,16 @@
1
+ 'use strict';
2
+
1
3
  exports.setPoweredBy = (app, res) => {
2
4
  if (app.enabled('x-powered-by')) {
3
5
  res.setHeader('X-Powered-By', 'HTTP/2 Express (http2-express)');
4
6
  }
5
- }
7
+ };
6
8
 
9
+ // Using optional chaining so a destroyed/reset stream never throws TypeError.
10
+ // req.stream?.session?.alpnProtocol returns undefined (not a crash) when the
11
+ // stream or session has already been closed.
7
12
  exports.isHttp2Request = (req) => {
8
- const alpnProtocol = req.httpVersion === '2.0' ? req.stream.session.alpnProtocol : 'h1';
9
- return alpnProtocol && (alpnProtocol === 'h2' || alpnProtocol === 'h2c');
10
- }
13
+ if (req.httpVersion !== '2.0') return false;
14
+ const alpnProtocol = req.stream?.session?.alpnProtocol;
15
+ return alpnProtocol === 'h2' || alpnProtocol === 'h2c';
16
+ };
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env"]
3
- }
package/.eslintrc DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "commonjs": true,
5
- "es2023": true
6
- },
7
- "extends": ["airbnb-base", "eslint:recommended"],
8
- "parserOptions": {
9
- "ecmaVersion": 14
10
- },
11
- "ignorePatterns":[
12
- "dist"
13
- ],
14
- "rules": {
15
- "no-console": "off",
16
- "comma-dangle": "off",
17
- "no-plusplus":"off",
18
- "no-case-declarations":"off",
19
- "no-restricted-syntax":"off",
20
- "no-await-in-loop":"off",
21
- "no-unused-vars":"warn",
22
- "max-len": [2, 250, 4, {"ignoreUrls": true}],
23
- "array-callback-return": "warn",
24
- "prefer-template": "warn",
25
- "prefer-const": "warn",
26
- "no-trailing-spaces": "warn",
27
- "no-multiple-empty-lines": "warn",
28
- "indent": "warn",
29
- "spaced-comment": "warn",
30
- "padded-blocks": "warn",
31
- "no-param-reassign": "warn",
32
- "no-path-concat": "warn",
33
- "arrow-body-style": "warn"
34
- }
35
- }
package/dist/core.js DELETED
@@ -1,157 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable func-names */
4
- /* eslint-disable no-underscore-dangle */
5
- var EventEmitter = require('events');
6
- var createHttp2Request = require('./http2Request');
7
- var createHttp2Response = require('./http2Response');
8
- var initHttp2Express = require('./initHttp2Express');
9
- var _require = require('./util'),
10
- setPoweredBy = _require.setPoweredBy,
11
- isHttp2Request = _require.isHttp2Request;
12
- var createHttp2Express = function createHttp2Express(express) {
13
- var application = express.application,
14
- request = express.request,
15
- response = express.response,
16
- Router = express.Router,
17
- query = express.query;
18
- var isExpress5 = !application.lazyrouter;
19
- if (isExpress5) {
20
- var originalInit = application.init;
21
- application.init = function init() {
22
- var _this = this;
23
- originalInit.call(this);
24
- // at this point we can use the router
25
- this.router.use(function (req, res, next) {
26
- setPoweredBy(_this, res);
27
- next();
28
- });
29
- };
30
- } else {
31
- application.lazyrouter = function lazyrouter() {
32
- if (!this._router) {
33
- this._router = new Router({
34
- caseSensitive: this.enabled('case sensitive routing'),
35
- strict: this.enabled('strict routing')
36
- });
37
- this._router.use(query(this.get('query parser fn')));
38
- this._router.use(initHttp2Express(this));
39
- }
40
- };
41
- }
42
- var oneshotRequestOverride = null;
43
- var oneshotResponseOverride = null;
44
- var _app = function app(req, res, next) {
45
- if (isExpress5 && isHttp2Request(req)) {
46
- // In Express 5, setting the prototype of req/res is done synchronously in the app.handle function,
47
- // so this is the right place to change the value of app.request/app.response.
48
- oneshotRequestOverride = _app.http2Request;
49
- oneshotResponseOverride = _app.http2Response;
50
- }
51
- _app.handle(req, res, next);
52
- };
53
-
54
- // Copying properties and descriptors from EventEmitter.prototype to app.
55
- Object.getOwnPropertyNames(EventEmitter.prototype).forEach(function (key) {
56
- var descriptor = Object.getOwnPropertyDescriptor(EventEmitter.prototype, key);
57
- if (descriptor) {
58
- Object.defineProperty(_app, key, descriptor);
59
- }
60
- });
61
-
62
- // Copy symbols from EventEmitter.prototype to app.
63
- Object.getOwnPropertySymbols(EventEmitter.prototype).forEach(function (symbol) {
64
- var descriptor = Object.getOwnPropertyDescriptor(EventEmitter.prototype, symbol);
65
- if (descriptor) {
66
- Object.defineProperty(_app, symbol, descriptor);
67
- }
68
- });
69
-
70
- // Copying properties from application to app.
71
- Object.getOwnPropertyNames(application).forEach(function (key) {
72
- var descriptor = Object.getOwnPropertyDescriptor(application, key);
73
- if (descriptor) {
74
- Object.defineProperty(_app, key, descriptor);
75
- }
76
- });
77
-
78
- // Copy symbols from application to app.
79
- Object.getOwnPropertySymbols(application).forEach(function (symbol) {
80
- var descriptor = Object.getOwnPropertyDescriptor(application, symbol);
81
- if (descriptor) {
82
- Object.defineProperty(_app, symbol, descriptor);
83
- }
84
- });
85
- response.push = function () {};
86
- _app._request = Object.create(request, {
87
- app: {
88
- configurable: true,
89
- enumerable: true,
90
- writable: true,
91
- value: _app
92
- }
93
- });
94
- _app._response = Object.create(response, {
95
- app: {
96
- configurable: true,
97
- enumerable: true,
98
- writable: true,
99
- value: _app
100
- }
101
- });
102
- var http2Request = createHttp2Request(request);
103
- var http2Response = createHttp2Response(response);
104
- _app.http2Request = Object.create(http2Request, {
105
- app: {
106
- configurable: true,
107
- enumerable: true,
108
- writable: true,
109
- value: _app
110
- }
111
- });
112
- _app.http2Response = Object.create(http2Response, {
113
- app: {
114
- configurable: true,
115
- enumerable: true,
116
- writable: true,
117
- value: _app
118
- }
119
- });
120
-
121
- // Expose the prototype that will get set on requests.
122
- Object.defineProperty(_app, 'request', {
123
- configurable: true,
124
- enumerable: true,
125
- get: function get() {
126
- if (oneshotRequestOverride) {
127
- var req = oneshotRequestOverride;
128
- oneshotRequestOverride = null;
129
- return req;
130
- }
131
- return _app._request;
132
- },
133
- set: function set(val) {
134
- _app._request = val;
135
- }
136
- });
137
-
138
- // Expose the prototype that will get set on responses.
139
- Object.defineProperty(_app, 'response', {
140
- configurable: true,
141
- enumerable: true,
142
- get: function get() {
143
- if (oneshotResponseOverride) {
144
- var res = oneshotResponseOverride;
145
- oneshotResponseOverride = null;
146
- return res;
147
- }
148
- return _app._response;
149
- },
150
- set: function set(val) {
151
- _app._response = val;
152
- }
153
- });
154
- _app.init();
155
- return _app;
156
- };
157
- module.exports = createHttp2Express;
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable dot-notation */
4
- var _require = require('http2'),
5
- Http2ServerRequest = _require.Http2ServerRequest;
6
- var createHttp2Request = function createHttp2Request(request) {
7
- var _Object$getOwnPropert;
8
- var http2Request = Object.create(Http2ServerRequest.prototype);
9
-
10
- // Copying properties and descriptors from request to http2Request.
11
- Object.getOwnPropertyNames(request).forEach(function (key) {
12
- var descriptor = Object.getOwnPropertyDescriptor(request, key);
13
- if (descriptor) {
14
- Object.defineProperty(http2Request, key, descriptor);
15
- }
16
- });
17
-
18
- // Retain symbols, if any, from request.
19
- Object.getOwnPropertySymbols(request).forEach(function (symbol) {
20
- var descriptor = Object.getOwnPropertyDescriptor(request, symbol);
21
- if (descriptor) {
22
- Object.defineProperty(http2Request, symbol, descriptor);
23
- }
24
- });
25
- var requestHostName = (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(http2Request, 'hostname')) === null || _Object$getOwnPropert === void 0 ? void 0 : _Object$getOwnPropert.get;
26
-
27
- // Redefine hostname property with custom getter.
28
- if (requestHostName) {
29
- Object.defineProperty(http2Request, 'hostname', {
30
- get: function get() {
31
- if (!this.headers['host'] && this.authority) {
32
- this.headers['host'] = this.authority;
33
- }
34
- return requestHostName.call(this);
35
- }
36
- });
37
- }
38
- return http2Request;
39
- };
40
- module.exports = createHttp2Request;
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- var _require = require('http2'),
4
- Http2ServerResponse = _require.Http2ServerResponse;
5
- var createHttp2Response = function createHttp2Response(response) {
6
- var http2Response = Object.create(Http2ServerResponse.prototype);
7
-
8
- // Copying properties and descriptors from response to http2Response.
9
- Object.getOwnPropertyNames(response).forEach(function (key) {
10
- var descriptor = Object.getOwnPropertyDescriptor(response, key);
11
- if (descriptor) {
12
- Object.defineProperty(http2Response, key, descriptor);
13
- }
14
- });
15
-
16
- // Copy symbols from response to http2Response.
17
- Object.getOwnPropertySymbols(response).forEach(function (symbol) {
18
- var descriptor = Object.getOwnPropertyDescriptor(response, symbol);
19
- if (descriptor) {
20
- Object.defineProperty(http2Response, symbol, descriptor);
21
- }
22
- });
23
- return http2Response;
24
- };
25
- module.exports = createHttp2Response;
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- var createHttp2Express = require('./core');
4
- module.exports = createHttp2Express;
5
- exports["default"] = createHttp2Express;
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- var _require = require("./util"),
4
- isHttp2Request = _require.isHttp2Request,
5
- setPoweredBy = _require.setPoweredBy;
6
- var initHttp2Express = function initHttp2Express(app) {
7
- return function (req, res, next) {
8
- setPoweredBy(app, res);
9
- req.res = res;
10
- res.req = req;
11
- req.next = next;
12
- if (isHttp2Request(req)) {
13
- Object.setPrototypeOf(req, app.http2Request);
14
- Object.setPrototypeOf(res, app.http2Response);
15
- } else {
16
- Object.setPrototypeOf(req, app.request);
17
- Object.setPrototypeOf(res, app.response);
18
- }
19
- res.locals = res.locals || Object.create(null);
20
- next();
21
- };
22
- };
23
- module.exports = initHttp2Express;
package/dist/util.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- exports.setPoweredBy = function (app, res) {
4
- if (app.enabled('x-powered-by')) {
5
- res.setHeader('X-Powered-By', 'HTTP/2 Express (http2-express)');
6
- }
7
- };
8
- exports.isHttp2Request = function (req) {
9
- var alpnProtocol = req.httpVersion === '2.0' ? req.stream.session.alpnProtocol : 'h1';
10
- return alpnProtocol && (alpnProtocol === 'h2' || alpnProtocol === 'h2c');
11
- };
@@ -1,21 +0,0 @@
1
- const { isHttp2Request, setPoweredBy } = require("./util");
2
-
3
- const initHttp2Express = (app) => (req, res, next) => {
4
- setPoweredBy(app, res);
5
- req.res = res;
6
- res.req = req;
7
- req.next = next;
8
-
9
- if (isHttp2Request(req)) {
10
- Object.setPrototypeOf(req, app.http2Request);
11
- Object.setPrototypeOf(res, app.http2Response);
12
- } else {
13
- Object.setPrototypeOf(req, app.request);
14
- Object.setPrototypeOf(res, app.response);
15
- }
16
-
17
- res.locals = res.locals || Object.create(null);
18
- next();
19
- };
20
-
21
- module.exports = initHttp2Express;