http: send connection: close when closing conn
HTTP/1.1 mandates connections which do not support keep-alive and close the connection send the connection: close header, see https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.10 This page also provides more information: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection I understand that HTTP/1.1 defaults to keep-alive - and that the Connection: close header is required when closing a connection. This adds the Connection: close header in the 400 and 414 responses sent on client errors. PR-URL: https://github.com/nodejs/node/pull/26467 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
914d908359
commit
c957b05177
@ -506,10 +506,12 @@ function onParserExecute(server, socket, parser, state, ret) {
|
|||||||
|
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
const badRequestResponse = Buffer.from(
|
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(
|
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) {
|
function socketOnError(e) {
|
||||||
// Ignore further errors
|
// Ignore further errors
|
||||||
|
@ -52,7 +52,9 @@ server.listen(0, common.mustCall(() => {
|
|||||||
received += data.toString();
|
received += data.toString();
|
||||||
}));
|
}));
|
||||||
c.on('end', common.mustCall(() => {
|
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.end();
|
||||||
}));
|
}));
|
||||||
c.on('close', common.mustCall(() => server.close()));
|
c.on('close', common.mustCall(() => server.close()));
|
||||||
|
@ -39,7 +39,8 @@ server.listen(0, mustCall(() => {
|
|||||||
c.on('end', mustCall(() => {
|
c.on('end', mustCall(() => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
received,
|
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();
|
c.end();
|
||||||
}));
|
}));
|
||||||
|
@ -37,7 +37,9 @@ server.listen(0, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('end', mustCall(() => {
|
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));
|
assert(Buffer.concat(chunks).equals(expected));
|
||||||
|
|
||||||
server.close();
|
server.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user