diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 0b7ed15622910d..c70d1f4d6d5409 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -211,7 +211,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableHighWaterMark', { ObjectDefineProperty(OutgoingMessage.prototype, 'writableCorked', { __proto__: null, get() { - return this[kCorked]; + return this[kSocket] ? this[kSocket].writableCorked : this[kCorked]; }, }); @@ -1000,9 +1000,9 @@ function write_(msg, chunk, encoding, callback, fromEnd) { } } - if (!fromEnd && msg.socket && !msg.socket.writableCorked) { - msg.socket.cork(); - process.nextTick(connectionCorkNT, msg.socket); + if (!fromEnd && !msg.writableCorked) { + msg.cork(); + process.nextTick(connectionUncorkNT, msg); } let ret; @@ -1027,8 +1027,8 @@ function write_(msg, chunk, encoding, callback, fromEnd) { } -function connectionCorkNT(conn) { - conn.uncork(); +function connectionUncorkNT(msg) { + msg.uncork(); } OutgoingMessage.prototype.addTrailers = function addTrailers(headers) { @@ -1143,9 +1143,9 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { // Fully uncork connection on end(). this[kSocket]._writableState.corked = 1; this[kSocket].uncork(); + } else { + this[kCorked] = 0; } - this[kCorked] = 1; - this.uncork(); this.finished = true;