11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// This test ensures that `addRequest`'s Legacy API accepts `localAddress` 51cb0ef41Sopenharmony_ci// correctly instead of accepting `path`. 61cb0ef41Sopenharmony_ci// https://github.com/nodejs/node/issues/5051 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ciconst agent = require('http').globalAgent; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci// Small stub just so we can call addRequest directly 121cb0ef41Sopenharmony_ciconst req = { 131cb0ef41Sopenharmony_ci getHeader: () => {} 141cb0ef41Sopenharmony_ci}; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciagent.maxSockets = 0; 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci// `localAddress` is used when naming requests / sockets while using the Legacy 191cb0ef41Sopenharmony_ci// API. Port 8080 is hardcoded since this does not create a network connection. 201cb0ef41Sopenharmony_ciagent.addRequest(req, 'localhost', 8080, '127.0.0.1'); 211cb0ef41Sopenharmony_ciassert.strictEqual(Object.keys(agent.requests).length, 1); 221cb0ef41Sopenharmony_ciassert.strictEqual( 231cb0ef41Sopenharmony_ci Object.keys(agent.requests)[0], 241cb0ef41Sopenharmony_ci 'localhost:8080:127.0.0.1'); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci// `path` is *not* used when naming requests / sockets. 271cb0ef41Sopenharmony_ci// Port 8080 is hardcoded since this does not create a network connection 281cb0ef41Sopenharmony_ciagent.addRequest(req, { 291cb0ef41Sopenharmony_ci host: 'localhost', 301cb0ef41Sopenharmony_ci port: 8080, 311cb0ef41Sopenharmony_ci localAddress: '127.0.0.1', 321cb0ef41Sopenharmony_ci path: '/foo' 331cb0ef41Sopenharmony_ci}); 341cb0ef41Sopenharmony_ciassert.strictEqual(Object.keys(agent.requests).length, 1); 351cb0ef41Sopenharmony_ciassert.strictEqual( 361cb0ef41Sopenharmony_ci Object.keys(agent.requests)[0], 371cb0ef41Sopenharmony_ci 'localhost:8080:127.0.0.1'); 38