Skip to content

Commit 9589641

Browse files
phouriMylesBorins
authored andcommitted
http2: Expose Http2ServerRequest/Response
In order for express (and possibly other libraries) to get and use the Http2ServerRequest/Response - expose them in the http2 exports. Same as is done in http module. PR-URL: #14690 Ref: expressjs/express#3390 Fixes: #14672 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 72cc2ca commit 9589641

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

lib/http2.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const {
1313
getUnpackedSettings,
1414
createServer,
1515
createSecureServer,
16-
connect
16+
connect,
17+
Http2ServerRequest,
18+
Http2ServerResponse,
1719
} = require('internal/http2/core');
1820

1921
module.exports = {
@@ -23,5 +25,7 @@ module.exports = {
2325
getUnpackedSettings,
2426
createServer,
2527
createSecureServer,
26-
connect
28+
connect,
29+
Http2ServerResponse,
30+
Http2ServerRequest,
2731
};

lib/internal/http2/compat.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,8 @@ function onServerStream(stream, headers, flags) {
573573
server.emit('request', request, response);
574574
}
575575

576-
module.exports = { onServerStream };
576+
module.exports = {
577+
onServerStream,
578+
Http2ServerRequest,
579+
Http2ServerResponse,
580+
};

lib/internal/http2/core.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const fs = require('fs');
1515
const errors = require('internal/errors');
1616
const { Duplex } = require('stream');
1717
const { URL } = require('url');
18-
const { onServerStream } = require('internal/http2/compat');
18+
const { onServerStream,
19+
Http2ServerRequest,
20+
Http2ServerResponse,
21+
} = require('internal/http2/compat');
1922
const { utcDate } = require('internal/http');
2023
const { _connectionListener: httpConnectionListener } = require('http');
2124
const { isUint8Array } = process.binding('util');
@@ -2552,7 +2555,9 @@ module.exports = {
25522555
getUnpackedSettings,
25532556
createServer,
25542557
createSecureServer,
2555-
connect
2558+
connect,
2559+
Http2ServerRequest,
2560+
Http2ServerResponse
25562561
};
25572562

25582563
/* eslint-enable no-use-before-define */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Flags: --expose-http2
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
const assert = require('assert');
8+
const http2 = require('http2');
9+
10+
const {
11+
Http2ServerRequest,
12+
Http2ServerResponse,
13+
} = http2;
14+
15+
const protoRequest = Object.create(Http2ServerRequest.prototype);
16+
const protoResponse = Object.create(Http2ServerResponse.prototype);
17+
18+
assert.strictEqual(protoRequest instanceof Http2ServerRequest, true);
19+
assert.strictEqual(protoResponse instanceof Http2ServerResponse, true);

0 commit comments

Comments
 (0)