node/test/parallel/test-http-head-response-has-no-body.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

37 lines
780 B
JavaScript

'use strict';
require('../common');
var assert = require('assert');
var http = require('http');
// This test is to make sure that when the HTTP server
// responds to a HEAD request, it does not send any body.
// In this case it was sending '0\r\n\r\n'
var server = http.createServer(function(req, res) {
res.writeHead(200); // broken: defaults to TE chunked
res.end();
});
server.listen(0);
var responseComplete = false;
server.on('listening', function() {
var req = http.request({
port: this.address().port,
method: 'HEAD',
path: '/'
}, function(res) {
res.on('end', function() {
server.close();
responseComplete = true;
});
res.resume();
});
req.end();
});
process.on('exit', function() {
assert.ok(responseComplete);
});