http2-express 1.0.1 → 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 +19 -1
- package/package.json +13 -14
- package/src/core.js +92 -20
- package/src/{http2Request.js → http2-request.js} +6 -14
- package/src/{http2Response.js → http2-response.js} +2 -0
- package/src/index.js +6 -1
- package/src/init-http2-express.js +33 -0
- package/src/util.js +16 -0
- package/.babelrc +0 -3
- package/.eslintrc +0 -35
- package/dist/core.js +0 -102
- package/dist/http2Request.js +0 -40
- package/dist/http2Response.js +0 -25
- package/dist/index.js +0 -5
- package/dist/initHttp2Express.js +0 -23
- package/dist/initHttp2ExpressOLD_ORIG.js +0 -24
- package/src/initHttp2Express.js +0 -23
- package/src/initHttp2ExpressOLD_ORIG.js +0 -22
package/README.md
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
# http2-express
|
|
2
2
|
This package adds HTTP/2 support to express.js applications.
|
|
3
3
|
|
|
4
|
-
**
|
|
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
|
+
|
|
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**.
|
|
16
|
+
This version is also backward compatible with Express 4.
|
|
17
|
+
<br>
|
|
18
|
+
<br>
|
|
5
19
|
|
|
6
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).
|
|
7
25
|
|
|
8
26
|
## Installation
|
|
9
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.
|
|
6
|
+
"version": "1.1.1",
|
|
5
7
|
"author": "Mark Jovis",
|
|
6
8
|
"contributors": [
|
|
7
|
-
"
|
|
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": "
|
|
21
|
-
"
|
|
22
|
+
"main": "src/index.js",
|
|
23
|
+
"files": ["src/"],
|
|
22
24
|
"scripts": {
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
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
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"
|
|
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,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
3
|
const EventEmitter = require('events');
|
|
4
4
|
|
|
5
|
-
const createHttp2Request = require('./
|
|
6
|
-
const createHttp2Response = require('./
|
|
7
|
-
const initHttp2Express = require('./
|
|
5
|
+
const createHttp2Request = require('./http2-request');
|
|
6
|
+
const createHttp2Response = require('./http2-response');
|
|
7
|
+
const initHttp2Express = require('./init-http2-express');
|
|
8
|
+
const { setPoweredBy, isHttp2Request } = require('./util');
|
|
8
9
|
|
|
9
10
|
const createHttp2Express = (express) => {
|
|
10
11
|
const {
|
|
@@ -15,18 +16,58 @@ const createHttp2Express = (express) => {
|
|
|
15
16
|
query
|
|
16
17
|
} = express;
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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';
|
|
25
|
+
|
|
26
|
+
if (isExpress5) {
|
|
27
|
+
const originalInit = application.init;
|
|
28
|
+
application.init = function init() {
|
|
29
|
+
originalInit.call(this);
|
|
30
|
+
this.router.use((req, res, next) => {
|
|
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
|
+
}
|
|
38
|
+
next();
|
|
23
39
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
application.lazyrouter = function lazyrouter() {
|
|
43
|
+
if (!this._router) {
|
|
44
|
+
this._router = new Router({
|
|
45
|
+
caseSensitive: this.enabled('case sensitive routing'),
|
|
46
|
+
strict: this.enabled('strict routing')
|
|
47
|
+
});
|
|
48
|
+
this._router.use(query(this.get('query parser fn')));
|
|
49
|
+
this._router.use(initHttp2Express(this));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
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).
|
|
63
|
+
let oneshotRequestOverride = null;
|
|
64
|
+
let oneshotResponseOverride = null;
|
|
28
65
|
|
|
29
66
|
const app = function (req, res, next) {
|
|
67
|
+
if (isExpress5 && isHttp2Request(req)) {
|
|
68
|
+
oneshotRequestOverride = app.http2Request;
|
|
69
|
+
oneshotResponseOverride = app.http2Response;
|
|
70
|
+
}
|
|
30
71
|
app.handle(req, res, next);
|
|
31
72
|
};
|
|
32
73
|
|
|
@@ -62,10 +103,7 @@ const createHttp2Express = (express) => {
|
|
|
62
103
|
}
|
|
63
104
|
});
|
|
64
105
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Expose the prototype that will get set on requests.
|
|
68
|
-
app.request = Object.create(request, {
|
|
106
|
+
app._request = Object.create(request, {
|
|
69
107
|
app: {
|
|
70
108
|
configurable: true,
|
|
71
109
|
enumerable: true,
|
|
@@ -74,8 +112,7 @@ const createHttp2Express = (express) => {
|
|
|
74
112
|
}
|
|
75
113
|
});
|
|
76
114
|
|
|
77
|
-
|
|
78
|
-
app.response = Object.create(response, {
|
|
115
|
+
app._response = Object.create(response, {
|
|
79
116
|
app: {
|
|
80
117
|
configurable: true,
|
|
81
118
|
enumerable: true,
|
|
@@ -84,6 +121,9 @@ const createHttp2Express = (express) => {
|
|
|
84
121
|
}
|
|
85
122
|
});
|
|
86
123
|
|
|
124
|
+
// No-op push on the per-app HTTP/1 response object only.
|
|
125
|
+
app._response.push = () => { };
|
|
126
|
+
|
|
87
127
|
const http2Request = createHttp2Request(request);
|
|
88
128
|
const http2Response = createHttp2Response(response);
|
|
89
129
|
|
|
@@ -104,6 +144,38 @@ const createHttp2Express = (express) => {
|
|
|
104
144
|
value: app
|
|
105
145
|
}
|
|
106
146
|
});
|
|
147
|
+
|
|
148
|
+
// No-op push on the per-app HTTP/2 response object only.
|
|
149
|
+
app.http2Response.push = () => { };
|
|
150
|
+
|
|
151
|
+
Object.defineProperty(app, 'request', {
|
|
152
|
+
configurable: true,
|
|
153
|
+
enumerable: true,
|
|
154
|
+
get() {
|
|
155
|
+
if (oneshotRequestOverride) {
|
|
156
|
+
const val = oneshotRequestOverride;
|
|
157
|
+
oneshotRequestOverride = null;
|
|
158
|
+
return val;
|
|
159
|
+
}
|
|
160
|
+
return app._request;
|
|
161
|
+
},
|
|
162
|
+
set(val) { app._request = val; }
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
Object.defineProperty(app, 'response', {
|
|
166
|
+
configurable: true,
|
|
167
|
+
enumerable: true,
|
|
168
|
+
get() {
|
|
169
|
+
if (oneshotResponseOverride) {
|
|
170
|
+
const val = oneshotResponseOverride;
|
|
171
|
+
oneshotResponseOverride = null;
|
|
172
|
+
return val;
|
|
173
|
+
}
|
|
174
|
+
return app._response;
|
|
175
|
+
},
|
|
176
|
+
set(val) { app._response = val; }
|
|
177
|
+
});
|
|
178
|
+
|
|
107
179
|
app.init();
|
|
108
180
|
return app;
|
|
109
181
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
|
|
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
|
};
|
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
|
-
|
|
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
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.setPoweredBy = (app, res) => {
|
|
4
|
+
if (app.enabled('x-powered-by')) {
|
|
5
|
+
res.setHeader('X-Powered-By', 'HTTP/2 Express (http2-express)');
|
|
6
|
+
}
|
|
7
|
+
};
|
|
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.
|
|
12
|
+
exports.isHttp2Request = (req) => {
|
|
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
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,102 +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 createHttp2Express = function createHttp2Express(express) {
|
|
10
|
-
var application = express.application,
|
|
11
|
-
request = express.request,
|
|
12
|
-
response = express.response,
|
|
13
|
-
Router = express.Router,
|
|
14
|
-
query = express.query;
|
|
15
|
-
application.lazyrouter = function lazyrouter() {
|
|
16
|
-
if (!this._router) {
|
|
17
|
-
this._router = new Router({
|
|
18
|
-
caseSensitive: this.enabled('case sensitive routing'),
|
|
19
|
-
strict: this.enabled('strict routing')
|
|
20
|
-
});
|
|
21
|
-
this._router.use(query(this.get('query parser fn')));
|
|
22
|
-
this._router.use(initHttp2Express(this));
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
var _app = function app(req, res, next) {
|
|
26
|
-
_app.handle(req, res, next);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Copying properties and descriptors from EventEmitter.prototype to app.
|
|
30
|
-
Object.getOwnPropertyNames(EventEmitter.prototype).forEach(function (key) {
|
|
31
|
-
var descriptor = Object.getOwnPropertyDescriptor(EventEmitter.prototype, key);
|
|
32
|
-
if (descriptor) {
|
|
33
|
-
Object.defineProperty(_app, key, descriptor);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Copy symbols from EventEmitter.prototype to app.
|
|
38
|
-
Object.getOwnPropertySymbols(EventEmitter.prototype).forEach(function (symbol) {
|
|
39
|
-
var descriptor = Object.getOwnPropertyDescriptor(EventEmitter.prototype, symbol);
|
|
40
|
-
if (descriptor) {
|
|
41
|
-
Object.defineProperty(_app, symbol, descriptor);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Copying properties from application to app.
|
|
46
|
-
Object.getOwnPropertyNames(application).forEach(function (key) {
|
|
47
|
-
var descriptor = Object.getOwnPropertyDescriptor(application, key);
|
|
48
|
-
if (descriptor) {
|
|
49
|
-
Object.defineProperty(_app, key, descriptor);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Copy symbols from application to app.
|
|
54
|
-
Object.getOwnPropertySymbols(application).forEach(function (symbol) {
|
|
55
|
-
var descriptor = Object.getOwnPropertyDescriptor(application, symbol);
|
|
56
|
-
if (descriptor) {
|
|
57
|
-
Object.defineProperty(_app, symbol, descriptor);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
response.push = function () {};
|
|
61
|
-
|
|
62
|
-
// Expose the prototype that will get set on requests.
|
|
63
|
-
_app.request = Object.create(request, {
|
|
64
|
-
app: {
|
|
65
|
-
configurable: true,
|
|
66
|
-
enumerable: true,
|
|
67
|
-
writable: true,
|
|
68
|
-
value: _app
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Expose the prototype that will get set on responses.
|
|
73
|
-
_app.response = Object.create(response, {
|
|
74
|
-
app: {
|
|
75
|
-
configurable: true,
|
|
76
|
-
enumerable: true,
|
|
77
|
-
writable: true,
|
|
78
|
-
value: _app
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
var http2Request = createHttp2Request(request);
|
|
82
|
-
var http2Response = createHttp2Response(response);
|
|
83
|
-
_app.http2Request = Object.create(http2Request, {
|
|
84
|
-
app: {
|
|
85
|
-
configurable: true,
|
|
86
|
-
enumerable: true,
|
|
87
|
-
writable: true,
|
|
88
|
-
value: _app
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
_app.http2Response = Object.create(http2Response, {
|
|
92
|
-
app: {
|
|
93
|
-
configurable: true,
|
|
94
|
-
enumerable: true,
|
|
95
|
-
writable: true,
|
|
96
|
-
value: _app
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
_app.init();
|
|
100
|
-
return _app;
|
|
101
|
-
};
|
|
102
|
-
module.exports = createHttp2Express;
|
package/dist/http2Request.js
DELETED
|
@@ -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;
|
package/dist/http2Response.js
DELETED
|
@@ -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
package/dist/initHttp2Express.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var initHttp2Express = function initHttp2Express(app) {
|
|
4
|
-
return function (req, res, next) {
|
|
5
|
-
if (app.enabled('x-powered-by')) {
|
|
6
|
-
res.setHeader('X-Powered-By', 'HTTP/2 Express (http2-express)');
|
|
7
|
-
}
|
|
8
|
-
req.res = res;
|
|
9
|
-
res.req = req;
|
|
10
|
-
req.next = next;
|
|
11
|
-
var alpnProtocol = req.httpVersion === '2.0' ? req.stream.session.alpnProtocol : 'h1';
|
|
12
|
-
if (alpnProtocol && (alpnProtocol === 'h2' || alpnProtocol === 'h2c')) {
|
|
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;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var initHttp2Express = function initHttp2Express(app) {
|
|
4
|
-
return function (req, res, next) {
|
|
5
|
-
if (app.enabled('x-powered-by')) {
|
|
6
|
-
res.setHeader('X-Powered-By', 'HTTP/2 Express (http2-express)');
|
|
7
|
-
}
|
|
8
|
-
req.res = res;
|
|
9
|
-
res.req = req;
|
|
10
|
-
req.next = next;
|
|
11
|
-
var _ref = req.httpVersion === '2.0' ? req.stream.session : req,
|
|
12
|
-
socket = _ref.socket;
|
|
13
|
-
if (socket.alpnProtocol && (socket.alpnProtocol === 'h2' || socket.alpnProtocol === 'h2c')) {
|
|
14
|
-
Object.setPrototypeOf(req, app.http2Request);
|
|
15
|
-
Object.setPrototypeOf(res, app.http2Response);
|
|
16
|
-
} else {
|
|
17
|
-
Object.setPrototypeOf(req, app.request);
|
|
18
|
-
Object.setPrototypeOf(res, app.response);
|
|
19
|
-
}
|
|
20
|
-
res.locals = res.locals || Object.create(null);
|
|
21
|
-
next();
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
module.exports = initHttp2Express;
|
package/src/initHttp2Express.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const initHttp2Express = (app) => (req, res, next) => {
|
|
2
|
-
if (app.enabled('x-powered-by')) {
|
|
3
|
-
res.setHeader('X-Powered-By', 'HTTP/2 Express (http2-express)');
|
|
4
|
-
}
|
|
5
|
-
req.res = res;
|
|
6
|
-
res.req = req;
|
|
7
|
-
req.next = next;
|
|
8
|
-
|
|
9
|
-
const alpnProtocol = req.httpVersion === '2.0' ? req.stream.session.alpnProtocol : 'h1';
|
|
10
|
-
|
|
11
|
-
if (alpnProtocol && (alpnProtocol === 'h2' || alpnProtocol === 'h2c')) {
|
|
12
|
-
Object.setPrototypeOf(req, app.http2Request);
|
|
13
|
-
Object.setPrototypeOf(res, app.http2Response);
|
|
14
|
-
} else {
|
|
15
|
-
Object.setPrototypeOf(req, app.request);
|
|
16
|
-
Object.setPrototypeOf(res, app.response);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
res.locals = res.locals || Object.create(null);
|
|
20
|
-
next();
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
module.exports = initHttp2Express;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const initHttp2Express = (app) => (req, res, next) => {
|
|
2
|
-
if (app.enabled('x-powered-by')) {
|
|
3
|
-
res.setHeader('X-Powered-By', 'HTTP/2 Express (http2-express)');
|
|
4
|
-
}
|
|
5
|
-
req.res = res;
|
|
6
|
-
res.req = req;
|
|
7
|
-
req.next = next;
|
|
8
|
-
|
|
9
|
-
const { socket } = req.httpVersion === '2.0' ? req.stream.session : req;
|
|
10
|
-
if (socket.alpnProtocol && (socket.alpnProtocol === 'h2' || socket.alpnProtocol === 'h2c')) {
|
|
11
|
-
Object.setPrototypeOf(req, app.http2Request);
|
|
12
|
-
Object.setPrototypeOf(res, app.http2Response);
|
|
13
|
-
} else {
|
|
14
|
-
Object.setPrototypeOf(req, app.request);
|
|
15
|
-
Object.setPrototypeOf(res, app.response);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
res.locals = res.locals || Object.create(null);
|
|
19
|
-
next();
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
module.exports = initHttp2Express;
|