mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
817 B
40 lines
817 B
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
const expectedSuccesses = [undefined, null, 'GET', 'post'];
|
|
let requestCount = 0;
|
|
|
|
const server = http.createServer((req, res) => {
|
|
requestCount++;
|
|
res.end();
|
|
|
|
if (expectedSuccesses.length === requestCount) {
|
|
server.close();
|
|
}
|
|
}).listen(0, test);
|
|
|
|
function test() {
|
|
function fail(input) {
|
|
assert.throws(() => {
|
|
http.request({ method: input, path: '/' }, common.fail);
|
|
}, /^TypeError: Method must be a string$/);
|
|
}
|
|
|
|
fail(-1);
|
|
fail(1);
|
|
fail(0);
|
|
fail({});
|
|
fail(true);
|
|
fail(false);
|
|
fail([]);
|
|
|
|
function ok(method) {
|
|
http.request({ method: method, port: server.address().port }).end();
|
|
}
|
|
|
|
expectedSuccesses.forEach((method) => {
|
|
ok(method);
|
|
});
|
|
}
|
|
|