File tree 3 files changed +50
-0
lines changed
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
1464
1464
buffer. Returns ` false ` if all or part of the data was queued in user memory.
1465
1465
` 'drain' ` will be emitted when the buffer is free again.
1466
1466
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
+
1467
1476
### response.writeContinue()
1468
1477
<!-- YAML
1469
1478
added: v0.3.0
Original file line number Diff line number Diff line change @@ -109,6 +109,15 @@ function OutgoingMessage() {
109
109
Object . setPrototypeOf ( OutgoingMessage . prototype , Stream . prototype ) ;
110
110
Object . setPrototypeOf ( OutgoingMessage , Stream ) ;
111
111
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
+ } ) ;
112
121
113
122
Object . defineProperty ( OutgoingMessage . prototype , '_headers' , {
114
123
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