@@ -136,36 +136,32 @@ OutgoingMessage.prototype._send = function _send(data, encoding, callback) {
136
136
137
137
OutgoingMessage . prototype . _writeRaw = _writeRaw ;
138
138
function _writeRaw ( data , encoding , callback ) {
139
+ const conn = this . connection ;
140
+ if ( conn && conn . destroyed ) {
141
+ // The socket was destroyed. If we're still trying to write to it,
142
+ // then we haven't gotten the 'close' event yet.
143
+ return false ;
144
+ }
145
+
139
146
if ( typeof encoding === 'function' ) {
140
147
callback = encoding ;
141
148
encoding = null ;
142
149
}
143
150
144
- var connection = this . connection ;
145
- if ( connection &&
146
- connection . _httpMessage === this &&
147
- connection . writable &&
148
- ! connection . destroyed ) {
151
+ if ( conn && conn . _httpMessage === this && conn . writable && ! conn . destroyed ) {
149
152
// There might be pending data in the this.output buffer.
150
- var outputLength = this . output . length ;
151
- if ( outputLength > 0 ) {
152
- this . _flushOutput ( connection ) ;
153
- } else if ( data . length === 0 ) {
153
+ if ( this . output . length ) {
154
+ this . _flushOutput ( conn ) ;
155
+ } else if ( ! data . length ) {
154
156
if ( typeof callback === 'function' )
155
157
process . nextTick ( callback ) ;
156
158
return true ;
157
159
}
158
-
159
160
// Directly write to socket.
160
- return connection . write ( data , encoding , callback ) ;
161
- } else if ( connection && connection . destroyed ) {
162
- // The socket was destroyed. If we're still trying to write to it,
163
- // then we haven't gotten the 'close' event yet.
164
- return false ;
165
- } else {
166
- // buffer, as long as we're not destroyed.
167
- return this . _buffer ( data , encoding , callback ) ;
161
+ return conn . write ( data , encoding , callback ) ;
168
162
}
163
+ // Buffer, as long as we're not destroyed.
164
+ return this . _buffer ( data , encoding , callback ) ;
169
165
}
170
166
171
167
@@ -477,6 +473,7 @@ Object.defineProperty(OutgoingMessage.prototype, 'headersSent', {
477
473
} ) ;
478
474
479
475
476
+ const crlf_buf = Buffer . from ( '\r\n' ) ;
480
477
OutgoingMessage . prototype . write = function write ( chunk , encoding , callback ) {
481
478
if ( this . finished ) {
482
479
var err = new Error ( 'write after end' ) ;
@@ -583,9 +580,6 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
583
580
}
584
581
} ;
585
582
586
-
587
- const crlf_buf = Buffer . from ( '\r\n' ) ;
588
-
589
583
function onFinish ( outmsg ) {
590
584
outmsg . emit ( 'finish' ) ;
591
585
}
0 commit comments