• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7if (!common.hasMultiLocalhost())
8  common.skip('platform-specific test.');
9
10const http2 = require('http2');
11const assert = require('assert');
12
13const server = http2.createServer((req, res) => {
14  console.log(`Connect from: ${req.connection.remoteAddress}`);
15  assert.strictEqual(req.connection.remoteAddress, '127.0.0.2');
16
17  req.on('end', common.mustCall(() => {
18    res.writeHead(200, { 'Content-Type': 'text/plain' });
19    res.end(`You are from: ${req.connection.remoteAddress}`);
20  }));
21  req.resume();
22});
23
24server.listen(0, '127.0.0.1', common.mustCall(() => {
25  const options = { localAddress: '127.0.0.2' };
26
27  const client = http2.connect(
28    'http://localhost:' + server.address().port,
29    options
30  );
31  const req = client.request({
32    ':path': '/'
33  });
34  req.on('data', () => req.resume());
35  req.on('end', common.mustCall(function() {
36    client.close();
37    req.close();
38    server.close();
39  }));
40  req.end();
41}));
42