0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/parallel/test-http-status-code.js
isaacs 3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00

47 lines
1.1 KiB
JavaScript

var common = require('../common');
var assert = require('assert');
var http = require('http');
// Simple test of Node's HTTP ServerResponse.statusCode
// ServerResponse.prototype.statusCode
var testsComplete = 0;
var tests = [200, 202, 300, 404, 500];
var testIdx = 0;
var s = http.createServer(function(req, res) {
var t = tests[testIdx];
res.writeHead(t, {'Content-Type': 'text/plain'});
console.log('--\nserver: statusCode after writeHead: ' + res.statusCode);
assert.equal(res.statusCode, t);
res.end('hello world\n');
});
s.listen(common.PORT, nextTest);
function nextTest() {
if (testIdx + 1 === tests.length) {
return s.close();
}
var test = tests[testIdx];
http.get({ port: common.PORT }, function(response) {
console.log('client: expected status: ' + test);
console.log('client: statusCode: ' + response.statusCode);
assert.equal(response.statusCode, test);
response.on('end', function() {
testsComplete++;
testIdx += 1;
nextTest();
});
response.resume();
});
}
process.on('exit', function() {
assert.equal(4, testsComplete);
});