@@ -135,7 +135,7 @@ OutgoingMessage.prototype._send = function(data, encoding, callback) {
135
135
this . outputEncodings . unshift ( 'binary' ) ;
136
136
this . outputCallbacks . unshift ( null ) ;
137
137
this . outputSize += this . _header . length ;
138
- if ( this . _onPendingData !== null )
138
+ if ( typeof this . _onPendingData === 'function' )
139
139
this . _onPendingData ( this . _header . length ) ;
140
140
}
141
141
this . _headerSent = true ;
@@ -158,22 +158,7 @@ OutgoingMessage.prototype._writeRaw = function(data, encoding, callback) {
158
158
// There might be pending data in the this.output buffer.
159
159
var outputLength = this . output . length ;
160
160
if ( outputLength > 0 ) {
161
- var output = this . output ;
162
- var outputEncodings = this . outputEncodings ;
163
- var outputCallbacks = this . outputCallbacks ;
164
- connection . cork ( ) ;
165
- for ( var i = 0 ; i < outputLength ; i ++ ) {
166
- connection . write ( output [ i ] , outputEncodings [ i ] ,
167
- outputCallbacks [ i ] ) ;
168
- }
169
- connection . uncork ( ) ;
170
-
171
- this . output = [ ] ;
172
- this . outputEncodings = [ ] ;
173
- this . outputCallbacks = [ ] ;
174
- if ( this . _onPendingData !== null )
175
- this . _onPendingData ( - this . outputSize ) ;
176
- this . outputSize = 0 ;
161
+ this . _flushOutput ( connection ) ;
177
162
} else if ( data . length === 0 ) {
178
163
if ( typeof callback === 'function' )
179
164
process . nextTick ( callback ) ;
@@ -198,7 +183,7 @@ OutgoingMessage.prototype._buffer = function(data, encoding, callback) {
198
183
this . outputEncodings . push ( encoding ) ;
199
184
this . outputCallbacks . push ( callback ) ;
200
185
this . outputSize += data . length ;
201
- if ( this . _onPendingData !== null )
186
+ if ( typeof this . _onPendingData === 'function' )
202
187
this . _onPendingData ( data . length ) ;
203
188
return false ;
204
189
} ;
@@ -644,26 +629,11 @@ OutgoingMessage.prototype._finish = function() {
644
629
// to attempt to flush any pending messages out to the socket.
645
630
OutgoingMessage . prototype . _flush = function ( ) {
646
631
var socket = this . socket ;
647
- var outputLength , ret ;
632
+ var ret ;
648
633
649
634
if ( socket && socket . writable ) {
650
635
// There might be remaining data in this.output; write it out
651
- outputLength = this . output . length ;
652
- if ( outputLength > 0 ) {
653
- var output = this . output ;
654
- var outputEncodings = this . outputEncodings ;
655
- var outputCallbacks = this . outputCallbacks ;
656
- socket . cork ( ) ;
657
- for ( var i = 0 ; i < outputLength ; i ++ ) {
658
- ret = socket . write ( output [ i ] , outputEncodings [ i ] ,
659
- outputCallbacks [ i ] ) ;
660
- }
661
- socket . uncork ( ) ;
662
-
663
- this . output = [ ] ;
664
- this . outputEncodings = [ ] ;
665
- this . outputCallbacks = [ ] ;
666
- }
636
+ ret = this . _flushOutput ( socket ) ;
667
637
668
638
if ( this . finished ) {
669
639
// This is a queue to the server or client to bring in the next this.
@@ -675,6 +645,32 @@ OutgoingMessage.prototype._flush = function() {
675
645
}
676
646
} ;
677
647
648
+ OutgoingMessage . prototype . _flushOutput = function _flushOutput ( socket ) {
649
+ var ret ;
650
+ var outputLength = this . output . length ;
651
+ if ( outputLength <= 0 )
652
+ return ret ;
653
+
654
+ var output = this . output ;
655
+ var outputEncodings = this . outputEncodings ;
656
+ var outputCallbacks = this . outputCallbacks ;
657
+ socket . cork ( ) ;
658
+ for ( var i = 0 ; i < outputLength ; i ++ ) {
659
+ ret = socket . write ( output [ i ] , outputEncodings [ i ] ,
660
+ outputCallbacks [ i ] ) ;
661
+ }
662
+ socket . uncork ( ) ;
663
+
664
+ this . output = [ ] ;
665
+ this . outputEncodings = [ ] ;
666
+ this . outputCallbacks = [ ] ;
667
+ if ( typeof this . _onPendingData === 'function' )
668
+ this . _onPendingData ( - this . outputSize ) ;
669
+ this . outputSize = 0 ;
670
+
671
+ return ret ;
672
+ } ;
673
+
678
674
679
675
OutgoingMessage . prototype . flushHeaders = function ( ) {
680
676
if ( ! this . _header ) {
0 commit comments