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());
|
2016-12-04 09:32:51 +01:00
|
|
|
}, /^TypeError: Method must be a string$/);
|
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
|
|
|
}));
|