Skip to content

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: #14690
Ref: expressjs/express#3390
Fixes: #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 MylesBorins committed Sep 10, 2017
1 parent c1ba027 commit df592b2
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
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
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
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
@@ -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 df592b2

Please sign in to comment.