Browse Source

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 <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
canary-base
Pini Houri 7 years ago
committed by Benjamin Gruenbaum
parent
commit
3f5d944ace
  1. 8
      lib/http2.js
  2. 6
      lib/internal/http2/compat.js
  3. 9
      lib/internal/http2/core.js
  4. 19
      test/parallel/test-http2-request-response-proto.js

8
lib/http2.js

@ -13,7 +13,9 @@ const {
getUnpackedSettings, getUnpackedSettings,
createServer, createServer,
createSecureServer, createSecureServer,
connect connect,
Http2ServerRequest,
Http2ServerResponse,
} = require('internal/http2/core'); } = require('internal/http2/core');
module.exports = { module.exports = {
@ -23,5 +25,7 @@ module.exports = {
getUnpackedSettings, getUnpackedSettings,
createServer, createServer,
createSecureServer, createSecureServer,
connect connect,
Http2ServerResponse,
Http2ServerRequest,
}; };

6
lib/internal/http2/compat.js

@ -573,4 +573,8 @@ function onServerStream(stream, headers, flags) {
server.emit('request', request, response); server.emit('request', request, response);
} }
module.exports = { onServerStream }; module.exports = {
onServerStream,
Http2ServerRequest,
Http2ServerResponse,
};

9
lib/internal/http2/core.js

@ -15,7 +15,10 @@ const fs = require('fs');
const errors = require('internal/errors'); const errors = require('internal/errors');
const { Duplex } = require('stream'); const { Duplex } = require('stream');
const { URL } = require('url'); const { URL } = require('url');
const { onServerStream } = require('internal/http2/compat'); const { onServerStream,
Http2ServerRequest,
Http2ServerResponse,
} = require('internal/http2/compat');
const { utcDate } = require('internal/http'); const { utcDate } = require('internal/http');
const { _connectionListener: httpConnectionListener } = require('http'); const { _connectionListener: httpConnectionListener } = require('http');
const { isUint8Array } = process.binding('util'); const { isUint8Array } = process.binding('util');
@ -2552,7 +2555,9 @@ module.exports = {
getUnpackedSettings, getUnpackedSettings,
createServer, createServer,
createSecureServer, createSecureServer,
connect connect,
Http2ServerRequest,
Http2ServerResponse
}; };
/* eslint-enable no-use-before-define */ /* eslint-enable no-use-before-define */

19
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);
Loading…
Cancel
Save