Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
http2: Expose Http2ServerRequest/Response
Browse files Browse the repository at this point in the history
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: nodejs/node#14690
Ref: expressjs/express#3390
Fixes: nodejs/node#14672
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
phouri authored and MSLaguana committed Aug 21, 2017
1 parent c717dae commit d0b6370
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const {
getUnpackedSettings,
createServer,
createSecureServer,
connect
connect,
Http2ServerRequest,
Http2ServerResponse,
} = require('internal/http2/core');

module.exports = {
Expand All @@ -23,5 +25,7 @@ module.exports = {
getUnpackedSettings,
createServer,
createSecureServer,
connect
connect,
Http2ServerResponse,
Http2ServerRequest,
};
6 changes: 5 additions & 1 deletion lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,8 @@ function onServerStream(stream, headers, flags) {
server.emit('request', request, response);
}

module.exports = { onServerStream };
module.exports = {
onServerStream,
Http2ServerRequest,
Http2ServerResponse,
};
9 changes: 7 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -2552,7 +2555,9 @@ module.exports = {
getUnpackedSettings,
createServer,
createSecureServer,
connect
connect,
Http2ServerRequest,
Http2ServerResponse
};

/* eslint-enable no-use-before-define */
19 changes: 19 additions & 0 deletions test/parallel/test-http2-request-response-proto.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit d0b6370

Please # to comment.