mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
509ff1b9e4
* use const instead of var * use common.mustCall to control functions execution * use assert.strictEqual instead of assert.equal * use arrow functions PR-URL: https://github.com/nodejs/node/pull/10503 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const http = require('http');
|
|
const assert = require('assert');
|
|
|
|
// first 204 or 304 works, subsequent anything fails
|
|
const codes = [204, 200];
|
|
|
|
// Methods don't really matter, but we put in something realistic.
|
|
const methods = ['DELETE', 'DELETE'];
|
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
|
const code = codes.shift();
|
|
assert.strictEqual(typeof code, 'number');
|
|
assert.ok(code > 0);
|
|
res.writeHead(code, {});
|
|
res.end();
|
|
}, codes.length));
|
|
|
|
function nextRequest() {
|
|
const method = methods.shift();
|
|
|
|
const request = http.request({
|
|
port: server.address().port,
|
|
method: method,
|
|
path: '/'
|
|
}, common.mustCall((response) => {
|
|
response.on('end', common.mustCall(() => {
|
|
if (methods.length === 0) {
|
|
server.close();
|
|
} else {
|
|
// throws error:
|
|
nextRequest();
|
|
// works just fine:
|
|
//process.nextTick(nextRequest);
|
|
}
|
|
}));
|
|
response.resume();
|
|
}));
|
|
request.end();
|
|
}
|
|
|
|
server.listen(0, nextRequest);
|