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.
47 lines
1.1 KiB
47 lines
1.1 KiB
14 years ago
|
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'});
|
||
13 years ago
|
console.log('--\nserver: statusCode after writeHead: ' + res.statusCode);
|
||
14 years ago
|
assert.equal(res.statusCode, t);
|
||
|
res.end('hello world\n');
|
||
|
});
|
||
|
|
||
|
s.listen(common.PORT, nextTest);
|
||
|
|
||
|
|
||
13 years ago
|
function nextTest() {
|
||
14 years ago
|
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();
|
||
|
});
|
||
12 years ago
|
response.resume();
|
||
14 years ago
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
process.on('exit', function() {
|
||
|
assert.equal(4, testsComplete);
|
||
|
});
|
||
|
|