• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Test that the family option of https.get is honored.
4
5const common = require('../common');
6if (!common.hasCrypto)
7  common.skip('missing crypto');
8
9if (!common.hasIPv6)
10  common.skip('no IPv6 support');
11
12const assert = require('assert');
13const fixtures = require('../common/fixtures');
14const https = require('https');
15
16{
17  // Test that `https` machinery passes host name, and receives IP.
18  const hostAddrIPv6 = '::1';
19  const HOSTNAME = 'dummy';
20  https.createServer({
21    cert: fixtures.readKey('agent1-cert.pem'),
22    key: fixtures.readKey('agent1-key.pem'),
23  }, common.mustCall(function(req, res) {
24    this.close();
25    res.end();
26  })).listen(0, hostAddrIPv6, common.mustCall(function() {
27    const options = {
28      host: HOSTNAME,
29      port: this.address().port,
30      family: 6,
31      rejectUnauthorized: false,
32      lookup: common.mustCall((addr, opt, cb) => {
33        assert.strictEqual(addr, HOSTNAME);
34        assert.strictEqual(opt.family, 6);
35        cb(null, hostAddrIPv6, opt.family);
36      })
37    };
38    // Will fail with ECONNREFUSED if the address family is not honored.
39    https.get(options, common.mustCall(function() {
40      assert.strictEqual(this.socket.remoteAddress, hostAddrIPv6);
41      this.destroy();
42    }));
43  }));
44}
45