mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
http: don't cork noop .end()
Calling .end() a second time should be a noop and not leave the socket corked. Fixes: https://github.com/nodejs/node/issues/36620 PR-URL: https://github.com/nodejs/node/pull/36633 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Danielle Adams <adamzdanielle@gmail.com>
This commit is contained in:
1 parent
2af43f6505
commit
1b669b2c12
2 files changed
+12
-4
No files matched your search
@@ -819,10 +819,6 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
if (this.socket) {
|
||||
this.socket.cork();
|
||||
}
|
||||
|
||||
if (chunk) {
|
||||
if (this.finished) {
|
||||
onError(this,
|
||||
@@ -830,6 +826,11 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
|
||||
typeof callback !== 'function' ? nop : callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
if (this.socket) {
|
||||
this.socket.cork();
|
||||
}
|
||||
|
||||
write_(this, chunk, encoding, null, true);
|
||||
} else if (this.finished) {
|
||||
if (typeof callback === 'function') {
|
||||
@@ -841,6 +842,10 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
|
||||
}
|
||||
return this;
|
||||
} else if (!this._header) {
|
||||
if (this.socket) {
|
||||
this.socket.cork();
|
||||
}
|
||||
|
||||
this._contentLength = 0;
|
||||
this._implicitHeader();
|
||||
}
|
||||
|
||||
@@ -9,10 +9,13 @@ const onWriteAfterEndError = common.mustCall((err) => {
|
||||
|
||||
const server = http.createServer(common.mustCall(function(req, res) {
|
||||
res.end('testing ended state', common.mustCall());
|
||||
assert.strictEqual(res.writableCorked, 0);
|
||||
res.end(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');
|
||||
}));
|
||||
assert.strictEqual(res.writableCorked, 0);
|
||||
res.end('end', onWriteAfterEndError);
|
||||
assert.strictEqual(res.writableCorked, 0);
|
||||
res.on('error', onWriteAfterEndError);
|
||||
res.on('finish', common.mustCall(() => {
|
||||
res.end(common.mustCall((err) => {
|
||||
|
||||
Reference in new issue
Block a user