node/test/parallel/test-http-status-message.js
Brian White 2bc7841d0f
test: use random ports where possible
This helps to prevent issues where a failed test can keep a bound
socket open long enough to cause other tests to fail with EADDRINUSE
because the same port number is used.

PR-URL: https://github.com/nodejs/node/pull/7045
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
2016-06-10 22:30:55 -04:00

31 lines
713 B
JavaScript

'use strict';
require('../common');
var assert = require('assert');
var http = require('http');
var net = require('net');
var s = http.createServer(function(req, res) {
res.statusCode = 200;
res.statusMessage = 'Custom Message';
res.end('');
});
s.listen(0, test);
function test() {
var bufs = [];
var client = net.connect(this.address().port, function() {
client.write('GET / HTTP/1.1\r\nConnection: close\r\n\r\n');
});
client.on('data', function(chunk) {
bufs.push(chunk);
});
client.on('end', function() {
var head = Buffer.concat(bufs).toString('latin1').split('\r\n')[0];
assert.equal('HTTP/1.1 200 Custom Message', head);
console.log('ok');
s.close();
});
}