From 11f592450b53b70ed202e55b168c9734e6ed8dce Mon Sep 17 00:00:00 2001 From: masx200 <34191203+masx200@users.noreply.github.com> Date: Tue, 15 Sep 2020 06:29:31 +0800 Subject: [PATCH] http2: add has method to proxySocketHandler PR-URL: https://github.com/nodejs/node/pull/35197 Reviewed-By: Matteo Collina Reviewed-By: Rich Trott --- lib/internal/http2/compat.js | 5 +++ ...test-http2-socket-proxy-handler-for-has.js | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test/parallel/test-http2-socket-proxy-handler-for-has.js diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index ec86be1ceaab45..e3cc240da1e1c6 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -188,6 +188,11 @@ function resumeStream(stream) { } const proxySocketHandler = { + has(stream, prop) { + const ref = stream.session !== undefined ? stream.session[kSocket] : stream; + return (prop in stream) || (prop in ref); + }, + get(stream, prop) { switch (prop) { case 'on': diff --git a/test/parallel/test-http2-socket-proxy-handler-for-has.js b/test/parallel/test-http2-socket-proxy-handler-for-has.js new file mode 100644 index 00000000000000..ccc63149ff1b12 --- /dev/null +++ b/test/parallel/test-http2-socket-proxy-handler-for-has.js @@ -0,0 +1,39 @@ +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) { + common.skip('missing crypto'); +} + +const fixtures = require('../common/fixtures'); +const assert = require('assert'); +const http2 = require('http2'); + +const serverOptions = { + key: fixtures.readKey('agent1-key.pem'), + cert: fixtures.readKey('agent1-cert.pem') +}; +const server = http2.createSecureServer(serverOptions, common.mustCall( + (req, res) => { + const request = req; + assert.strictEqual(request.socket.encrypted, true); + assert.ok('encrypted' in request.socket); + res.end(); + } +)); +server.listen(common.mustCall(() => { + const port = server.address().port; + const client = http2.connect('https://localhost:' + port, { + ca: fixtures.readKey('agent1-cert.pem'), + rejectUnauthorized: false + }); + const req = client.request({}); + req.on('response', common.mustCall((headers, flags) => { + console.log(headers); + server.close(common.mustCall(() => { + })); + })); + req.on('end', common.mustCall(() => { + client.close(); + })); + req.end(); +}));