2016-12-04 09:32:51 +01:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
2017-07-15 00:05:24 +02:00
|
|
|
const Countdown = require('../common/countdown');
|
2016-12-04 09:32:51 +01:00
|
|
|
|
|
|
|
const expectedSuccesses = [undefined, null, 'GET', 'post'];
|
2017-07-15 00:05:24 +02:00
|
|
|
const expectedFails = [-1, 1, 0, {}, true, false, [], Symbol()];
|
2016-12-04 09:32:51 +01:00
|
|
|
|
2017-07-15 00:05:24 +02:00
|
|
|
const countdown =
|
|
|
|
new Countdown(expectedSuccesses.length,
|
|
|
|
common.mustCall(() => server.close()));
|
2016-12-04 09:32:51 +01:00
|
|
|
|
2017-07-15 00:05:24 +02:00
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
|
|
|
res.end();
|
|
|
|
countdown.dec();
|
|
|
|
}, expectedSuccesses.length));
|
2016-12-04 09:32:51 +01:00
|
|
|
|
2017-07-15 00:05:24 +02:00
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
expectedFails.forEach((method) => {
|
2016-12-04 09:32:51 +01:00
|
|
|
assert.throws(() => {
|
2017-07-15 00:05:24 +02:00
|
|
|
http.request({ method, path: '/' }, common.mustNotCall());
|
2017-07-22 13:23:04 +02:00
|
|
|
}, common.expectsError({
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'The "method" argument must be of type string. ' +
|
|
|
|
`Received type ${typeof method}`
|
|
|
|
}));
|
2017-07-15 00:05:24 +02:00
|
|
|
});
|
2016-12-04 09:32:51 +01:00
|
|
|
|
|
|
|
expectedSuccesses.forEach((method) => {
|
2017-07-15 00:05:24 +02:00
|
|
|
http.request({ method, port: server.address().port }).end();
|
2016-12-04 09:32:51 +01:00
|
|
|
});
|
2017-07-15 00:05:24 +02:00
|
|
|
}));
|