@@ -146,6 +146,7 @@ const kSession = Symbol('session');
146146const kState = Symbol ( 'state' ) ;
147147const kType = Symbol ( 'type' ) ;
148148const kUpdateTimer = Symbol ( 'update-timer' ) ;
149+ const kWriteGeneric = Symbol ( 'write-generic' ) ;
149150
150151const kDefaultSocketTimeout = 2 * 60 * 1000 ;
151152
@@ -1657,13 +1658,16 @@ class Http2Stream extends Duplex {
16571658 'bug in Node.js' ) ;
16581659 }
16591660
1660- _write ( data , encoding , cb ) {
1661+ [ kWriteGeneric ] ( writev , data , encoding , cb ) {
16611662 // When the Http2Stream is first created, it is corked until the
16621663 // handle and the stream ID is assigned. However, if the user calls
16631664 // uncork() before that happens, the Duplex will attempt to pass
16641665 // writes through. Those need to be queued up here.
16651666 if ( this . pending ) {
1666- this . once ( 'ready' , this . _write . bind ( this , data , encoding , cb ) ) ;
1667+ this . once (
1668+ 'ready' ,
1669+ this [ kWriteGeneric ] . bind ( this , writev , data , encoding , cb )
1670+ ) ;
16671671 return ;
16681672 }
16691673
@@ -1683,41 +1687,20 @@ class Http2Stream extends Duplex {
16831687 const req = createWriteWrap ( this [ kHandle ] , afterDoStreamWrite ) ;
16841688 req . stream = this [ kID ] ;
16851689
1686- writeGeneric ( this , req , data , encoding , cb ) ;
1690+ if ( writev )
1691+ writevGeneric ( this , req , data , cb ) ;
1692+ else
1693+ writeGeneric ( this , req , data , encoding , cb ) ;
16871694
16881695 trackWriteState ( this , req . bytes ) ;
16891696 }
16901697
1691- _writev ( data , cb ) {
1692- // When the Http2Stream is first created, it is corked until the
1693- // handle and the stream ID is assigned. However, if the user calls
1694- // uncork() before that happens, the Duplex will attempt to pass
1695- // writes through. Those need to be queued up here.
1696- if ( this . pending ) {
1697- this . once ( 'ready' , this . _writev . bind ( this , data , cb ) ) ;
1698- return ;
1699- }
1700-
1701- // If the stream has been destroyed, there's nothing else we can do
1702- // because the handle has been destroyed. This should only be an
1703- // issue if a write occurs before the 'ready' event in the case where
1704- // the duplex is uncorked before the stream is ready to go. In that
1705- // case, drop the data on the floor. An error should have already been
1706- // emitted.
1707- if ( this . destroyed )
1708- return ;
1709-
1710- this [ kUpdateTimer ] ( ) ;
1711-
1712- if ( ! this . headersSent )
1713- this [ kProceed ] ( ) ;
1714-
1715- var req = createWriteWrap ( this [ kHandle ] , afterDoStreamWrite ) ;
1716- req . stream = this [ kID ] ;
1717-
1718- writevGeneric ( this , req , data , cb ) ;
1698+ _write ( data , encoding , cb ) {
1699+ this [ kWriteGeneric ] ( false , data , encoding , cb ) ;
1700+ }
17191701
1720- trackWriteState ( this , req . bytes ) ;
1702+ _writev ( data , cb ) {
1703+ this [ kWriteGeneric ] ( true , data , '' , cb ) ;
17211704 }
17221705
17231706 _final ( cb ) {
0 commit comments