diff --git a/lib/_http_server.js b/lib/_http_server.js index 02cd7a81a9cc0b..15671a2c81e628 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -507,10 +507,12 @@ function onParserExecute(server, socket, parser, state, ret) { const noop = () => {}; const badRequestResponse = Buffer.from( - `HTTP/1.1 400 ${STATUS_CODES[400]}${CRLF}${CRLF}`, 'ascii' + `HTTP/1.1 400 ${STATUS_CODES[400]}${CRLF}` + + `Connection: close${CRLF}${CRLF}`, 'ascii' ); const requestHeaderFieldsTooLargeResponse = Buffer.from( - `HTTP/1.1 431 ${STATUS_CODES[431]}${CRLF}${CRLF}`, 'ascii' + `HTTP/1.1 431 ${STATUS_CODES[431]}${CRLF}` + + `Connection: close${CRLF}${CRLF}`, 'ascii' ); function socketOnError(e) { // Ignore further errors diff --git a/test/parallel/test-http-blank-header.js b/test/parallel/test-http-blank-header.js index fd447b46d213a9..696b16f4995b57 100644 --- a/test/parallel/test-http-blank-header.js +++ b/test/parallel/test-http-blank-header.js @@ -52,7 +52,9 @@ server.listen(0, common.mustCall(() => { received += data.toString(); })); c.on('end', common.mustCall(() => { - assert.strictEqual(received, 'HTTP/1.1 400 Bad Request\r\n\r\n'); + assert.strictEqual(received, + 'HTTP/1.1 400 Bad Request\r\n' + + 'Connection: close\r\n\r\n'); c.end(); })); c.on('close', common.mustCall(() => server.close())); diff --git a/test/parallel/test-http-header-overflow.js b/test/parallel/test-http-header-overflow.js index a9bf5cbfa08601..167dada928801c 100644 --- a/test/parallel/test-http-header-overflow.js +++ b/test/parallel/test-http-header-overflow.js @@ -39,7 +39,8 @@ server.listen(0, mustCall(() => { c.on('end', mustCall(() => { assert.strictEqual( received, - 'HTTP/1.1 431 Request Header Fields Too Large\r\n\r\n' + 'HTTP/1.1 431 Request Header Fields Too Large\r\n' + + 'Connection: close\r\n\r\n' ); c.end(); })); diff --git a/test/parallel/test-http-server-destroy-socket-on-client-error.js b/test/parallel/test-http-server-destroy-socket-on-client-error.js index 9d51364183385b..7085401883933b 100644 --- a/test/parallel/test-http-server-destroy-socket-on-client-error.js +++ b/test/parallel/test-http-server-destroy-socket-on-client-error.js @@ -37,7 +37,9 @@ server.listen(0, () => { }); socket.on('end', mustCall(() => { - const expected = Buffer.from('HTTP/1.1 400 Bad Request\r\n\r\n'); + const expected = Buffer.from( + 'HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n' + ); assert(Buffer.concat(chunks).equals(expected)); server.close();