2016-02-11 01:59:25 +01:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const agent = require('http').globalAgent;
|
|
|
|
|
|
|
|
// small stub just so we can call addRequest directly
|
|
|
|
const req = {
|
2017-03-24 17:46:44 +01:00
|
|
|
getHeader: common.noop
|
2016-02-11 01:59:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
agent.maxSockets = 0;
|
|
|
|
|
|
|
|
// localAddress is used when naming requests / sockets
|
|
|
|
// while using the Legacy API
|
2017-04-26 08:21:41 +02:00
|
|
|
// port 8080 is hardcoded since this does not create a network connection
|
|
|
|
agent.addRequest(req, 'localhost', 8080, '127.0.0.1');
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(Object.keys(agent.requests).length, 1);
|
|
|
|
assert.strictEqual(
|
2016-02-11 01:59:25 +01:00
|
|
|
Object.keys(agent.requests)[0],
|
2017-04-26 08:21:41 +02:00
|
|
|
'localhost:8080:127.0.0.1');
|
2016-02-11 01:59:25 +01:00
|
|
|
|
|
|
|
// path is *not* used when naming requests / sockets
|
2017-04-26 08:21:41 +02:00
|
|
|
// port 8080 is hardcoded since this does not create a network connection
|
2016-02-11 01:59:25 +01:00
|
|
|
agent.addRequest(req, {
|
|
|
|
host: 'localhost',
|
2017-04-26 08:21:41 +02:00
|
|
|
port: 8080,
|
2016-02-11 01:59:25 +01:00
|
|
|
localAddress: '127.0.0.1',
|
|
|
|
path: '/foo'
|
|
|
|
});
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(Object.keys(agent.requests).length, 1);
|
|
|
|
assert.strictEqual(
|
2016-02-11 01:59:25 +01:00
|
|
|
Object.keys(agent.requests)[0],
|
2017-04-26 08:21:41 +02:00
|
|
|
'localhost:8080:127.0.0.1');
|