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: be more aggressive to reply 400, 408 and 431 #44818

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/api/http.md
Expand Up @@ -1311,8 +1311,9 @@ type other than {net.Socket}.

Default behavior is to try close the socket with a HTTP '400 Bad Request',
or a HTTP '431 Request Header Fields Too Large' in the case of a
[`HPE_HEADER_OVERFLOW`][] error. If the socket is not writable or has already
written data it is immediately destroyed.
[`HPE_HEADER_OVERFLOW`][] error. If the socket is not writable or headers
of the current attached [`http.ServerResponse`][] has been sent, it is
immediately destroyed.

`socket` is the [`net.Socket`][] object that the error originated from.

Expand Down
6 changes: 5 additions & 1 deletion lib/_http_server.js
Expand Up @@ -823,7 +823,11 @@ function socketOnError(e) {
}

if (!this.server.emit('clientError', e, this)) {
if (this.writable && this.bytesWritten === 0) {
// Cautions must be taken to avoid corrupting the remote peer,
// reply an error segment if no in-flight ServerResponse
// or data of the in-flight one is not yet written to this socket
ywave620 marked this conversation as resolved.
Show resolved Hide resolved
if (this.writable &&
(!this._httpMessage || !this._httpMessage._headerSent)) {
let response;

switch (e.code) {
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-http-server-headers-timeout-keepalive.js
Expand Up @@ -81,9 +81,7 @@ server.listen(0, common.mustCall(() => {
assert.strictEqual(second, true);
assert.strictEqual(
response,
// Empty because of https://github.com/nodejs/node/commit/e8d7fedf7cad6e612e4f2e0456e359af57608ac7
// 'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
''
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
);
server.close();
});
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-http-server-headers-timeout-pipelining.js
Expand Up @@ -56,9 +56,7 @@ server.listen(0, common.mustCall(() => {

assert.strictEqual(
response,
// Empty because of https://github.com/nodejs/node/commit/e8d7fedf7cad6e612e4f2e0456e359af57608ac7
// 'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
''
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
);
server.close();
});
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-http-server-request-timeout-keepalive.js
Expand Up @@ -79,9 +79,7 @@ server.listen(0, common.mustCall(() => {
assert.strictEqual(second, true);
assert.strictEqual(
response,
// Empty because of https://github.com/nodejs/node/commit/e8d7fedf7cad6e612e4f2e0456e359af57608ac7
// 'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
''
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
);
server.close();
});
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-http-server-request-timeout-pipelining.js
Expand Up @@ -50,9 +50,7 @@ server.listen(0, common.mustCall(() => {

assert.strictEqual(
response,
// Empty because of https://github.com/nodejs/node/commit/e8d7fedf7cad6e612e4f2e0456e359af57608ac7
// 'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
''
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
);
server.close();
});
Expand Down