11cb0ef41Sopenharmony_ci// Flags: --expose-internals 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciif (!common.hasMultiLocalhost()) 81cb0ef41Sopenharmony_ci common.skip('platform-specific test.'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst http2 = require('http2'); 111cb0ef41Sopenharmony_ciconst assert = require('assert'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst server = http2.createServer((req, res) => { 141cb0ef41Sopenharmony_ci console.log(`Connect from: ${req.connection.remoteAddress}`); 151cb0ef41Sopenharmony_ci assert.strictEqual(req.connection.remoteAddress, '127.0.0.2'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci req.on('end', common.mustCall(() => { 181cb0ef41Sopenharmony_ci res.writeHead(200, { 'Content-Type': 'text/plain' }); 191cb0ef41Sopenharmony_ci res.end(`You are from: ${req.connection.remoteAddress}`); 201cb0ef41Sopenharmony_ci })); 211cb0ef41Sopenharmony_ci req.resume(); 221cb0ef41Sopenharmony_ci}); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciserver.listen(0, '127.0.0.1', common.mustCall(() => { 251cb0ef41Sopenharmony_ci const options = { localAddress: '127.0.0.2', family: 4 }; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci const client = http2.connect( 281cb0ef41Sopenharmony_ci 'http://localhost:' + server.address().port, 291cb0ef41Sopenharmony_ci options 301cb0ef41Sopenharmony_ci ); 311cb0ef41Sopenharmony_ci const req = client.request({ 321cb0ef41Sopenharmony_ci ':path': '/' 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci req.on('data', () => req.resume()); 351cb0ef41Sopenharmony_ci req.on('end', common.mustCall(function() { 361cb0ef41Sopenharmony_ci client.close(); 371cb0ef41Sopenharmony_ci req.close(); 381cb0ef41Sopenharmony_ci server.close(); 391cb0ef41Sopenharmony_ci })); 401cb0ef41Sopenharmony_ci req.end(); 411cb0ef41Sopenharmony_ci})); 42