Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: send connection: close on client error #26467

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-http-blank-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http-header-overflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down