File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -1464,6 +1464,15 @@ Returns `true` if the entire data was flushed successfully to the kernel
14641464buffer. Returns ` false ` if all or part of the data was queued in user memory.
14651465` 'drain' ` will be emitted when the buffer is free again.
14661466
1467+ ### response.writableFinished
1468+ <!-- YAML
1469+ added: REPLACEME
1470+ -->
1471+
1472+ * {boolean}
1473+
1474+ Is ` true ` if all data has been flushed to the underlying system.
1475+
14671476### response.writeContinue()
14681477<!-- YAML
14691478added: v0.3.0
Original file line number Diff line number Diff line change @@ -109,6 +109,15 @@ function OutgoingMessage() {
109109Object . setPrototypeOf ( OutgoingMessage . prototype , Stream . prototype ) ;
110110Object . setPrototypeOf ( OutgoingMessage , Stream ) ;
111111
112+ Object . defineProperty ( OutgoingMessage . prototype , 'writableFinished' , {
113+ get : function ( ) {
114+ return (
115+ this . finished &&
116+ this . outputSize === 0 &&
117+ ( ! this . socket || this . socket . writableLength === 0 )
118+ ) ;
119+ }
120+ } ) ;
112121
113122Object . defineProperty ( OutgoingMessage . prototype , '_headers' , {
114123 get : internalUtil . deprecate ( function ( ) {
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+ const http = require ( 'http' ) ;
5+
6+ const server = http . createServer ( common . mustCall ( function ( req , res ) {
7+ assert . strictEqual ( res . writableFinished , false ) ;
8+ res
9+ . on ( 'finish' , common . mustCall ( ( ) => {
10+ assert . strictEqual ( res . writableFinished , true ) ;
11+ server . close ( ) ;
12+ } ) )
13+ . end ( ) ;
14+ } ) ) ;
15+
16+ server . listen ( 0 ) ;
17+
18+ server . on ( 'listening' , common . mustCall ( function ( ) {
19+ const clientRequest = http . request ( {
20+ port : server . address ( ) . port ,
21+ method : 'GET' ,
22+ path : '/'
23+ } ) ;
24+
25+ assert . strictEqual ( clientRequest . writableFinished , false ) ;
26+ clientRequest
27+ . on ( 'finish' , common . mustCall ( ( ) => {
28+ assert . strictEqual ( clientRequest . writableFinished , true ) ;
29+ } ) )
30+ . end ( ) ;
31+ assert . strictEqual ( clientRequest . writableFinished , false ) ;
32+ } ) ) ;
You can’t perform that action at this time.
0 commit comments