11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst http = require('http'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst baseOptions = { 71cb0ef41Sopenharmony_ci method: 'GET', 81cb0ef41Sopenharmony_ci port: undefined, 91cb0ef41Sopenharmony_ci host: common.localhostIPv4, 101cb0ef41Sopenharmony_ci}; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst failingAgentOptions = [ 131cb0ef41Sopenharmony_ci true, 141cb0ef41Sopenharmony_ci 'agent', 151cb0ef41Sopenharmony_ci {}, 161cb0ef41Sopenharmony_ci 1, 171cb0ef41Sopenharmony_ci () => null, 181cb0ef41Sopenharmony_ci Symbol(), 191cb0ef41Sopenharmony_ci]; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciconst acceptableAgentOptions = [ 221cb0ef41Sopenharmony_ci false, 231cb0ef41Sopenharmony_ci undefined, 241cb0ef41Sopenharmony_ci null, 251cb0ef41Sopenharmony_ci new http.Agent(), 261cb0ef41Sopenharmony_ci]; 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ciconst server = http.createServer((req, res) => { 291cb0ef41Sopenharmony_ci res.end('hello'); 301cb0ef41Sopenharmony_ci}); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_cilet numberOfResponses = 0; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cifunction createRequest(agent) { 351cb0ef41Sopenharmony_ci const options = Object.assign(baseOptions, { agent }); 361cb0ef41Sopenharmony_ci const request = http.request(options); 371cb0ef41Sopenharmony_ci request.end(); 381cb0ef41Sopenharmony_ci request.on('response', common.mustCall(() => { 391cb0ef41Sopenharmony_ci numberOfResponses++; 401cb0ef41Sopenharmony_ci if (numberOfResponses === acceptableAgentOptions.length) { 411cb0ef41Sopenharmony_ci server.close(); 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci })); 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ciserver.listen(0, baseOptions.host, common.mustCall(function() { 471cb0ef41Sopenharmony_ci baseOptions.port = this.address().port; 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci failingAgentOptions.forEach((agent) => { 501cb0ef41Sopenharmony_ci assert.throws( 511cb0ef41Sopenharmony_ci () => createRequest(agent), 521cb0ef41Sopenharmony_ci { 531cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 541cb0ef41Sopenharmony_ci name: 'TypeError', 551cb0ef41Sopenharmony_ci message: 'The "options.agent" property must be one of Agent-like ' + 561cb0ef41Sopenharmony_ci 'Object, undefined, or false.' + 571cb0ef41Sopenharmony_ci common.invalidArgTypeHelper(agent) 581cb0ef41Sopenharmony_ci } 591cb0ef41Sopenharmony_ci ); 601cb0ef41Sopenharmony_ci }); 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci acceptableAgentOptions.forEach((agent) => { 631cb0ef41Sopenharmony_ci createRequest(agent); 641cb0ef41Sopenharmony_ci }); 651cb0ef41Sopenharmony_ci})); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ciprocess.on('exit', () => { 681cb0ef41Sopenharmony_ci assert.strictEqual(numberOfResponses, acceptableAgentOptions.length); 691cb0ef41Sopenharmony_ci}); 70