Skip to content

Commit

Permalink
http2: add has method to proxySocketHandler
Browse files Browse the repository at this point in the history
PR-URL: #35197
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
masx200 authored and danielleadams committed Nov 9, 2020
1 parent 71fa9c6 commit 11f5924
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
39 changes: 39 additions & 0 deletions test/parallel/test-http2-socket-proxy-handler-for-has.js
Original file line number Diff line number Diff line change
@@ -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();
}));

0 comments on commit 11f5924

Please sign in to comment.