2017-04-18 13:33:51 -07:00
|
|
|
'use strict';
|
2017-07-03 14:00:41 -07:00
|
|
|
require('../common');
|
2017-06-29 16:21:23 -07:00
|
|
|
|
2017-04-18 13:33:51 -07:00
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
|
|
|
|
|
|
|
// All of these values should cause http.request() to throw synchronously
|
|
|
|
// when passed as the value of either options.hostname or options.host
|
|
|
|
const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()];
|
|
|
|
|
2017-06-18 16:22:32 +03:00
|
|
|
const errHostname =
|
|
|
|
/^TypeError: "options\.hostname" must either be a string, undefined or null$/;
|
|
|
|
const errHost =
|
|
|
|
/^TypeError: "options\.host" must either be a string, undefined or null$/;
|
2017-04-18 13:33:51 -07:00
|
|
|
|
|
|
|
vals.forEach((v) => {
|
2017-07-10 20:55:21 -04:00
|
|
|
assert.throws(() => http.request({ hostname: v }), errHostname);
|
|
|
|
assert.throws(() => http.request({ host: v }), errHost);
|
2017-04-18 13:33:51 -07:00
|
|
|
});
|
|
|
|
|
2017-07-04 10:04:54 -04:00
|
|
|
// These values are OK and should not throw synchronously.
|
|
|
|
// Only testing for 'hostname' validation so ignore connection errors.
|
|
|
|
const dontCare = () => {};
|
2017-04-18 13:33:51 -07:00
|
|
|
['', undefined, null].forEach((v) => {
|
|
|
|
assert.doesNotThrow(() => {
|
2017-07-10 20:55:21 -04:00
|
|
|
http.request({ hostname: v }).on('error', dontCare).end();
|
|
|
|
http.request({ host: v }).on('error', dontCare).end();
|
2017-04-18 13:33:51 -07:00
|
|
|
});
|
|
|
|
});
|