From 07c55d28444fdfb584abf082a70bea7f9f86b9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 6 Jun 2021 11:51:23 +0200 Subject: [PATCH] Revert "http: make HEAD method to work with keep-alive" This reverts commit 7afa5336aed999a62e4943e6000a239585b2e2ea. The change breaks clients like cURL. Fixes: https://github.com/nodejs/node/issues/38922 PR-URL: https://github.com/nodejs/node/pull/38949 Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Mary Marchini Reviewed-By: Michael Dawson Reviewed-By: Robert Nagy Reviewed-By: Jiawen Geng --- lib/_http_outgoing.js | 3 +- test/parallel/test-http-reuse-socket.js | 51 ------------------------- 2 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 test/parallel/test-http-reuse-socket.js diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 7736c31c4d41a8..27a1f4454c1581 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -447,8 +447,7 @@ function _storeHeader(firstLine, headers) { } if (!state.contLen && !state.te) { - if (!this._hasBody && (this.statusCode === 204 || - this.statusCode === 304)) { + if (!this._hasBody) { // Make sure we don't end the 0\r\n\r\n at the end of the message. this.chunkedEncoding = false; } else if (!this.useChunkedEncodingByDefault) { diff --git a/test/parallel/test-http-reuse-socket.js b/test/parallel/test-http-reuse-socket.js deleted file mode 100644 index f5cd002fdbf519..00000000000000 --- a/test/parallel/test-http-reuse-socket.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; -const common = require('../common'); -const http = require('http'); -const assert = require('assert'); -const Countdown = require('../common/countdown'); - -// The HEAD:204, GET:200 is the most pathological test case. -// GETs following a 204 response with a content-encoding header failed. -// Responses without bodies and without content-length or encoding caused -// the socket to be closed. -const codes = [204, 200, 200, 304, 200]; -const methods = ['HEAD', 'HEAD', 'GET', 'HEAD', 'GET']; - -const sockets = []; -const agent = new http.Agent(); -agent.maxSockets = 1; - -const countdown = new Countdown(codes.length, () => server.close()); - -const server = http.createServer(common.mustCall((req, res) => { - const code = codes.shift(); - assert.strictEqual(typeof code, 'number'); - assert.ok(code > 0); - res.writeHead(code, {}); - res.end(); -}, codes.length)); - -function nextRequest() { - const request = http.request({ - port: server.address().port, - path: '/', - agent: agent, - method: methods.shift() - }, common.mustCall((response) => { - response.on('end', common.mustCall(() => { - if (countdown.dec()) { - nextRequest(); - } - assert.strictEqual(sockets.length, 1); - })); - response.resume(); - })); - request.on('socket', common.mustCall((socket) => { - if (!sockets.includes(socket)) { - sockets.push(socket); - } - })); - request.end(); -} - -server.listen(0, common.mustCall(nextRequest));