2016-02-10 22:59:25 -02:00
|
|
|
'use strict';
|
2017-05-03 21:07:54 -07:00
|
|
|
require('../common');
|
2018-03-11 01:35:40 +05:30
|
|
|
|
|
|
|
// This test ensures that `addRequest`'s Legacy API accepts `localAddress`
|
|
|
|
// correctly instead of accepting `path`.
|
|
|
|
// https://github.com/nodejs/node/issues/5051
|
|
|
|
|
2016-02-10 22:59:25 -02:00
|
|
|
const assert = require('assert');
|
|
|
|
const agent = require('http').globalAgent;
|
|
|
|
|
2018-12-10 13:27:32 +01:00
|
|
|
// Small stub just so we can call addRequest directly
|
2016-02-10 22:59:25 -02:00
|
|
|
const req = {
|
2017-05-03 21:07:54 -07:00
|
|
|
getHeader: () => {}
|
2016-02-10 22:59:25 -02:00
|
|
|
};
|
|
|
|
|
|
|
|
agent.maxSockets = 0;
|
|
|
|
|
2019-01-21 01:22:27 +01:00
|
|
|
// `localAddress` is used when naming requests / sockets while using the Legacy
|
|
|
|
// API. Port 8080 is hardcoded since this does not create a network connection.
|
2017-04-26 09:21:41 +03:00
|
|
|
agent.addRequest(req, 'localhost', 8080, '127.0.0.1');
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(Object.keys(agent.requests).length, 1);
|
|
|
|
assert.strictEqual(
|
2016-02-10 22:59:25 -02:00
|
|
|
Object.keys(agent.requests)[0],
|
2017-04-26 09:21:41 +03:00
|
|
|
'localhost:8080:127.0.0.1');
|
2016-02-10 22:59:25 -02:00
|
|
|
|
2019-01-21 01:22:27 +01:00
|
|
|
// `path` is *not* used when naming requests / sockets.
|
|
|
|
// Port 8080 is hardcoded since this does not create a network connection
|
2016-02-10 22:59:25 -02:00
|
|
|
agent.addRequest(req, {
|
|
|
|
host: 'localhost',
|
2017-04-26 09:21:41 +03:00
|
|
|
port: 8080,
|
2016-02-10 22:59:25 -02:00
|
|
|
localAddress: '127.0.0.1',
|
|
|
|
path: '/foo'
|
|
|
|
});
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(Object.keys(agent.requests).length, 1);
|
|
|
|
assert.strictEqual(
|
2016-02-10 22:59:25 -02:00
|
|
|
Object.keys(agent.requests)[0],
|
2017-04-26 09:21:41 +03:00
|
|
|
'localhost:8080:127.0.0.1');
|