Skip to content

Commit 30f5772

Browse files
committed
fixup! http: align with stream.Writable
1 parent 7991c78 commit 30f5772

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/_http_outgoing.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const {
3838
ObjectPrototypeHasOwnProperty,
3939
ObjectSetPrototypeOf,
4040
RegExpPrototypeTest,
41-
StringPrototypeToLowerCase
41+
StringPrototypeToLowerCase,
42+
Symbol,
4243
} = primordials;
4344

4445
const { getDefaultHighWaterMark } = require('internal/streams/state');
@@ -80,6 +81,8 @@ const { construct, destroy } = require('internal/streams/destroy');
8081
const HIGH_WATER_MARK = getDefaultHighWaterMark();
8182
const { CRLF, debug } = common;
8283

84+
const kCorked = Symbol('kCorked');
85+
8386
const nop = FunctionPrototype;
8487

8588
const RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i;
@@ -120,6 +123,7 @@ function OutgoingMessage(opts) {
120123
this._trailer = '';
121124

122125
this._headerSent = false;
126+
this[kCorked] = 0;
123127

124128
this.socket = null;
125129
this._header = null;
@@ -283,6 +287,8 @@ OutgoingMessage.prototype.cork = function() {
283287

284288
if (this.socket) {
285289
this.socket.cork();
290+
} else {
291+
this[kCorked]++;
286292
}
287293
};
288294

@@ -293,6 +299,8 @@ OutgoingMessage.prototype.uncork = function() {
293299

294300
if (this.socket) {
295301
this.socket.uncork();
302+
} else if (this[kCorked]) {
303+
this[kCorked]--;
296304
}
297305
};
298306

@@ -313,14 +321,14 @@ OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
313321

314322
OutgoingMessage.prototype._construct = function(callback) {
315323
if (this.socket) {
316-
for (let n = 0; n < this._writableState.corked; ++n) {
324+
for (let n = 0; n < this[kCorked]; ++n) {
317325
this.socket.cork();
318326
}
319327
callback();
320328
} else {
321329
// TODO(ronag): What if never assigned socket?
322330
this.once('socket', function(socket) {
323-
for (let n = 0; n < this._writableState.corked; ++n) {
331+
for (let n = 0; n < this[kCorked]; ++n) {
324332
socket.cork();
325333
}
326334
callback();
@@ -772,7 +780,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
772780

773781
if (!fromEnd && !state.corked) {
774782
msg.cork();
775-
process.nextTick(connectionCorkNT, msg);
783+
process.nextTick(uncorkNT, msg);
776784
}
777785

778786
let ret;
@@ -790,8 +798,8 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
790798
}
791799

792800

793-
function connectionCorkNT(conn) {
794-
conn.uncork();
801+
function uncorkNT(msg) {
802+
msg.uncork();
795803
}
796804

797805

0 commit comments

Comments
 (0)