node/test/parallel/test-http-no-content-length.js
Brian White 9a8acad6ff 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-07-14 12:45:24 -07:00

26 lines
593 B
JavaScript

'use strict';
require('../common');
var assert = require('assert');
var net = require('net');
var http = require('http');
var body = '';
var server = net.createServer(function(socket) {
// Neither Content-Length nor Connection
socket.end('HTTP/1.1 200 ok\r\n\r\nHello');
}).listen(0, function() {
http.get({port: this.address().port}, function(res) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
server.close();
});
});
});
process.on('exit', function() {
assert.equal(body, 'Hello');
});