• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3
4// This test ensures that `addRequest`'s Legacy API accepts `localAddress`
5// correctly instead of accepting `path`.
6// https://github.com/nodejs/node/issues/5051
7
8const assert = require('assert');
9const agent = require('http').globalAgent;
10
11// Small stub just so we can call addRequest directly
12const req = {
13  getHeader: () => {}
14};
15
16agent.maxSockets = 0;
17
18// `localAddress` is used when naming requests / sockets while using the Legacy
19// API. Port 8080 is hardcoded since this does not create a network connection.
20agent.addRequest(req, 'localhost', 8080, '127.0.0.1');
21assert.strictEqual(Object.keys(agent.requests).length, 1);
22assert.strictEqual(
23  Object.keys(agent.requests)[0],
24  'localhost:8080:127.0.0.1');
25
26// `path` is *not* used when naming requests / sockets.
27// Port 8080 is hardcoded since this does not create a network connection
28agent.addRequest(req, {
29  host: 'localhost',
30  port: 8080,
31  localAddress: '127.0.0.1',
32  path: '/foo'
33});
34assert.strictEqual(Object.keys(agent.requests).length, 1);
35assert.strictEqual(
36  Object.keys(agent.requests)[0],
37  'localhost:8080:127.0.0.1');
38