forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: support passing options of http2.connect to net.connect
PR-URL: nodejs#29816 Fixes: nodejs#29811 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
if (!common.hasMultiLocalhost()) | ||
common.skip('platform-specific test.'); | ||
|
||
const http2 = require('http2'); | ||
const assert = require('assert'); | ||
|
||
const server = http2.createServer((req, res) => { | ||
console.log(`Connect from: ${req.connection.remoteAddress}`); | ||
assert.strictEqual(req.connection.remoteAddress, '127.0.0.2'); | ||
|
||
req.on('end', common.mustCall(() => { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(`You are from: ${req.connection.remoteAddress}`); | ||
})); | ||
req.resume(); | ||
}); | ||
|
||
server.listen(0, '127.0.0.1', common.mustCall(() => { | ||
const options = { localAddress: '127.0.0.2' }; | ||
|
||
const client = http2.connect( | ||
'http://localhost:' + server.address().port, | ||
options | ||
); | ||
const req = client.request({ | ||
':path': '/' | ||
}); | ||
req.on('data', () => req.resume()); | ||
req.on('end', common.mustCall(function() { | ||
client.close(); | ||
req.close(); | ||
server.close(); | ||
process.exit(); | ||
})); | ||
req.end(); | ||
})); |