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: close the connection after sending a body without declared length #46333

Merged
Merged
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
4 changes: 4 additions & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ function _storeHeader(firstLine, headers) {
// Transfer-Encoding are removed by the user.
// See: test/parallel/test-http-remove-header-stays-removed.js
debug('Both Content-Length and Transfer-Encoding are removed');

// We can't keep alive in this case, because with no header info the body
// is defined as all data until the connection is closed.
this._last = true;
}
}

Expand Down
9 changes: 7 additions & 2 deletions test/parallel/test-http-remove-header-stays-removed.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const server = http.createServer(function(request, response) {
response.setHeader('date', 'coffee o clock');

response.end('beep boop\n');

this.close();
});

let response = '';
Expand All @@ -57,5 +55,12 @@ server.listen(0, function() {
res.on('data', function(chunk) {
response += chunk;
});

setTimeout(function() {
// The socket should be closed immediately, with no keep-alive, because
// no content-length or transfer-encoding are used:
assert.strictEqual(res.socket.closed, true);
server.close();
}, 10);
});
});