1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const http = require('http'); 6 7// All of these values should cause http.request() to throw synchronously 8// when passed as the value of either options.hostname or options.host 9const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()]; 10 11vals.forEach((v) => { 12 const received = common.invalidArgTypeHelper(v); 13 assert.throws( 14 () => http.request({ hostname: v }), 15 { 16 code: 'ERR_INVALID_ARG_TYPE', 17 name: 'TypeError', 18 message: 'The "options.hostname" property must be of ' + 19 'type string or one of undefined or null.' + 20 received 21 } 22 ); 23 24 assert.throws( 25 () => http.request({ host: v }), 26 { 27 code: 'ERR_INVALID_ARG_TYPE', 28 name: 'TypeError', 29 message: 'The "options.host" property must be of ' + 30 'type string or one of undefined or null.' + 31 received 32 } 33 ); 34}); 35 36// These values are OK and should not throw synchronously. 37// Only testing for 'hostname' validation so ignore connection errors. 38const dontCare = () => {}; 39['', undefined, null].forEach((v) => { 40 http.request({ hostname: v }).on('error', dontCare).end(); 41 http.request({ host: v }).on('error', dontCare).end(); 42}); 43