2017-04-18 13:33:51 -07:00
|
|
|
'use strict';
|
2017-06-29 16:21:23 -07:00
|
|
|
|
2017-07-22 19:23:04 +08:00
|
|
|
const common = require('../common');
|
2019-12-25 18:02:16 +01:00
|
|
|
const assert = require('assert');
|
2017-04-18 13:33:51 -07:00
|
|
|
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()];
|
|
|
|
|
|
|
|
vals.forEach((v) => {
|
2019-09-23 08:17:25 +02:00
|
|
|
const received = common.invalidArgTypeHelper(v);
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(
|
2017-07-22 19:23:04 +08:00
|
|
|
() => http.request({ hostname: v }),
|
2017-12-06 21:08:06 +05:30
|
|
|
{
|
2017-07-22 19:23:04 +08:00
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2019-09-23 08:17:25 +02:00
|
|
|
message: 'The "options.hostname" property must be of ' +
|
|
|
|
'type string or one of undefined or null.' +
|
|
|
|
received
|
2017-12-06 21:08:06 +05:30
|
|
|
}
|
2017-07-22 19:23:04 +08:00
|
|
|
);
|
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(
|
2017-07-22 19:23:04 +08:00
|
|
|
() => http.request({ host: v }),
|
2017-12-06 21:08:06 +05:30
|
|
|
{
|
2017-07-22 19:23:04 +08:00
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2019-09-23 08:17:25 +02:00
|
|
|
message: 'The "options.host" property must be of ' +
|
|
|
|
'type string or one of undefined or null.' +
|
|
|
|
received
|
2017-12-06 21:08:06 +05:30
|
|
|
}
|
2017-07-22 19:23:04 +08:00
|
|
|
);
|
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 = () => {};
|
2023-12-22 07:06:01 +01:00
|
|
|
const values = ['', undefined, null];
|
|
|
|
for (const v of values) {
|
2018-02-09 02:32:04 +01:00
|
|
|
http.request({ hostname: v }).on('error', dontCare).end();
|
|
|
|
http.request({ host: v }).on('error', dontCare).end();
|
2023-12-22 07:06:01 +01:00
|
|
|
}
|