diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index ea3d7e62556212..ae62e62c5671b7 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -548,6 +548,10 @@ function _storeHeader(firstLine, headers) { // Transfer-Encoding are removed by the user. // See: test/parallel/test-http-remove-header-stays-removed.js debug('Both Content-Length and Transfer-Encoding are removed'); + + // We can't keep alive in this case, because with no header info the body + // is defined as all data until the connection is closed. + this._last = true; } } diff --git a/test/parallel/test-http-remove-header-stays-removed.js b/test/parallel/test-http-remove-header-stays-removed.js index 3885ebd905f758..92c1e45dd25d01 100644 --- a/test/parallel/test-http-remove-header-stays-removed.js +++ b/test/parallel/test-http-remove-header-stays-removed.js @@ -37,8 +37,6 @@ const server = http.createServer(function(request, response) { response.setHeader('date', 'coffee o clock'); response.end('beep boop\n'); - - this.close(); }); let response = ''; @@ -57,5 +55,12 @@ server.listen(0, function() { res.on('data', function(chunk) { response += chunk; }); + + setTimeout(function() { + // The socket should be closed immediately, with no keep-alive, because + // no content-length or transfer-encoding are used: + assert.strictEqual(res.socket.closed, true); + server.close(); + }, 10); }); });