node/test/parallel/test-http-status-code.js
Max Barinov 1c5d4f2453 http: 451 status code "Unavailable For Legal Reasons"
This http code allows us to provide a fair reason when
we can't return some data to the client by legal issues.

IETF https://datatracker.ietf.org/doc/draft-ietf-httpbis-legally-restricted-status/

Fixes: #4376
PR-URL: https://github.com/nodejs/node/pull/4377
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-12-23 17:31:26 -08:00

48 lines
1.1 KiB
JavaScript

'use strict';
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, 451, 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(5, testsComplete);
});