From 9589641c5cdf16b94edde59c137c59f51299bb50 Mon Sep 17 00:00:00 2001 From: Pini Houri Date: Fri, 11 Aug 2017 00:12:28 +0300 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/14690 Ref: https://github.com/expressjs/express/issues/3390 Fixes: https://github.com/nodejs/node/issues/14672 Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Matteo Collina --- lib/http2.js | 8 ++++++-- lib/internal/http2/compat.js | 6 +++++- lib/internal/http2/core.js | 9 +++++++-- .../test-http2-request-response-proto.js | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-http2-request-response-proto.js diff --git a/lib/http2.js b/lib/http2.js index e964abf589d0eb..ab9e33b2a2a859 100644 --- a/lib/http2.js +++ b/lib/http2.js @@ -13,7 +13,9 @@ const { getUnpackedSettings, createServer, createSecureServer, - connect + connect, + Http2ServerRequest, + Http2ServerResponse, } = require('internal/http2/core'); module.exports = { @@ -23,5 +25,7 @@ module.exports = { getUnpackedSettings, createServer, createSecureServer, - connect + connect, + Http2ServerResponse, + Http2ServerRequest, }; diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 100e08a25df92b..c2ada307dda675 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -573,4 +573,8 @@ function onServerStream(stream, headers, flags) { server.emit('request', request, response); } -module.exports = { onServerStream }; +module.exports = { + onServerStream, + Http2ServerRequest, + Http2ServerResponse, +}; diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index c3681383f87e80..92d8e6077c9c75 100755 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -15,7 +15,10 @@ const fs = require('fs'); const errors = require('internal/errors'); const { Duplex } = require('stream'); const { URL } = require('url'); -const { onServerStream } = require('internal/http2/compat'); +const { onServerStream, + Http2ServerRequest, + Http2ServerResponse, +} = require('internal/http2/compat'); const { utcDate } = require('internal/http'); const { _connectionListener: httpConnectionListener } = require('http'); const { isUint8Array } = process.binding('util'); @@ -2552,7 +2555,9 @@ module.exports = { getUnpackedSettings, createServer, createSecureServer, - connect + connect, + Http2ServerRequest, + Http2ServerResponse }; /* eslint-enable no-use-before-define */ diff --git a/test/parallel/test-http2-request-response-proto.js b/test/parallel/test-http2-request-response-proto.js new file mode 100644 index 00000000000000..3bbf8e86434489 --- /dev/null +++ b/test/parallel/test-http2-request-response-proto.js @@ -0,0 +1,19 @@ +// Flags: --expose-http2 +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); +const assert = require('assert'); +const http2 = require('http2'); + +const { + Http2ServerRequest, + Http2ServerResponse, +} = http2; + +const protoRequest = Object.create(Http2ServerRequest.prototype); +const protoResponse = Object.create(Http2ServerResponse.prototype); + +assert.strictEqual(protoRequest instanceof Http2ServerRequest, true); +assert.strictEqual(protoResponse instanceof Http2ServerResponse, true);