| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bb19d82 commit f9b61d2
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -764,6 +764,27 @@ req.once('response', (res) => { | |||
| 764 | 764 | }); | |
| 765 | 765 | ``` | |
| 766 | 766 | ||
| 767 | + ### request.writableEnded | ||
| 768 | + <!-- YAML | ||
| 769 | + added: REPLACEME | ||
| 770 | + --> | ||
| 771 | + | ||
| 772 | + * {boolean} | ||
| 773 | + | ||
| 774 | + Is `true` after [`request.end()`][] has been called. This property | ||
| 775 | + does not indicate whether the data has been flushed, for this use | ||
| 776 | + [`request.writableFinished`][] instead. | ||
| 777 | + | ||
| 778 | + ### request.writableFinished | ||
| 779 | + <!-- YAML | ||
| 780 | + added: v12.7.0 | ||
| 781 | + --> | ||
| 782 | + | ||
| 783 | + * {boolean} | ||
| 784 | + | ||
| 785 | + Is `true` if all data has been flushed to the underlying system, immediately | ||
| 786 | + before the [`'finish'`][] event is emitted. | ||
| 787 | + | ||
| 767 | 788 | ### request.write(chunk[, encoding][, callback]) | |
| 768 | 789 | <!-- YAML | |
| 769 | 790 | added: v0.1.29 | |
@@ -1434,6 +1455,17 @@ response.statusMessage = 'Not found'; | |||
| 1434 | 1455 | After response header was sent to the client, this property indicates the | |
| 1435 | 1456 | status message which was sent out. | |
| 1436 | 1457 | ||
| 1458 | + ### response.writableEnded | ||
| 1459 | + <!-- YAML | ||
| 1460 | + added: REPLACEME | ||
| 1461 | + --> | ||
| 1462 | + | ||
| 1463 | + * {boolean} | ||
| 1464 | + | ||
| 1465 | + Is `true` after [`response.end()`][] has been called. This property | ||
| 1466 | + does not indicate whether the data has been flushed, for this use | ||
| 1467 | + [`response.writableFinished`][] instead. | ||
| 1468 | + | ||
| 1437 | 1469 | ### response.writableFinished | |
| 1438 | 1470 | <!-- YAML | |
| 1439 | 1471 | added: v12.7.0 | |
@@ -2221,11 +2253,13 @@ not abort the request or do anything besides add a `'timeout'` event. | |||
| 2221 | 2253 | [`request.setTimeout()`]: #http_request_settimeout_timeout_callback | |
| 2222 | 2254 | [`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed | |
| 2223 | 2255 | [`request.socket`]: #http_request_socket | |
| 2256 | + [`request.writableFinished`]: #http_request_writablefinished | ||
| 2224 | 2257 | [`request.write(data, encoding)`]: #http_request_write_chunk_encoding_callback | |
| 2225 | 2258 | [`response.end()`]: #http_response_end_data_encoding_callback | |
| 2226 | 2259 | [`response.getHeader()`]: #http_response_getheader_name | |
| 2227 | 2260 | [`response.setHeader()`]: #http_response_setheader_name_value | |
| 2228 | 2261 | [`response.socket`]: #http_response_socket | |
| 2262 | + [`response.writableFinished`]: #http_response_writablefinished | ||
| 2229 | 2263 | [`response.write()`]: #http_response_write_chunk_encoding_callback | |
| 2230 | 2264 | [`response.write(data, encoding)`]: #http_response_write_chunk_encoding_callback | |
| 2231 | 2265 | [`response.writeContinue()`]: #http_response_writecontinue | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3269,6 +3269,17 @@ added: v8.4.0 | |||
| 3269 | 3269 | ||
| 3270 | 3270 | The [`Http2Stream`][] object backing the response. | |
| 3271 | 3271 | ||
| 3272 | + #### response.writableEnded | ||
| 3273 | + <!-- YAML | ||
| 3274 | + added: REPLACEME | ||
| 3275 | + --> | ||
| 3276 | + | ||
| 3277 | + * {boolean} | ||
| 3278 | + | ||
| 3279 | + Is `true` after [`response.end()`][] has been called. This property | ||
| 3280 | + does not indicate whether the data has been flushed, for this use | ||
| 3281 | + [`writable.writableFinished`][] instead. | ||
| 3282 | + | ||
| 3272 | 3283 | #### response.write(chunk[, encoding][, callback]) | |
| 3273 | 3284 | <!-- YAML | |
| 3274 | 3285 | added: v8.4.0 | |
@@ -3509,3 +3520,4 @@ following additional properties: | |||
| 3509 | 3520 | [`tls.connect()`]: tls.html#tls_tls_connect_options_callback | |
| 3510 | 3521 | [`tls.createServer()`]: tls.html#tls_tls_createserver_options_secureconnectionlistener | |
| 3511 | 3522 | [error code]: #error_codes | |
| 3523 | + [`writable.writableFinished`]: stream.html#stream_writable_writablefinished | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -491,6 +491,17 @@ added: v11.4.0 | |||
| 491 | 491 | ||
| 492 | 492 | Is `true` if it is safe to call [`writable.write()`][stream-write]. | |
| 493 | 493 | ||
| 494 | + ##### writable.writableEnded | ||
| 495 | + <!-- YAML | ||
| 496 | + added: REPLACEME | ||
| 497 | + --> | ||
| 498 | + | ||
| 499 | + * {boolean} | ||
| 500 | + | ||
| 501 | + Is `true` after [`writable.end()`][] has been called. This property | ||
| 502 | + does not indicate whether the data has been flushed, for this use | ||
| 503 | + [`writable.writableFinished`][] instead. | ||
| 504 | + | ||
| 494 | 505 | ##### writable.writableFinished | |
| 495 | 506 | <!-- YAML | |
| 496 | 507 | added: v12.6.0 | |
@@ -2704,7 +2715,9 @@ contain multi-byte characters. | |||
| 2704 | 2715 | [`stream.unpipe()`]: #stream_readable_unpipe_destination | |
| 2705 | 2716 | [`stream.wrap()`]: #stream_readable_wrap_stream | |
| 2706 | 2717 | [`writable.cork()`]: #stream_writable_cork | |
| 2718 | + [`writable.end()`]: #stream_writable_end_chunk_encoding_callback | ||
| 2707 | 2719 | [`writable.uncork()`]: #stream_writable_uncork | |
| 2720 | + [`writable.writableFinished`]: #stream_writable_writablefinished | ||
| 2708 | 2721 | [`zlib.createDeflate()`]: zlib.html#zlib_zlib_createdeflate_options | |
| 2709 | 2722 | [API for Stream Consumers]: #stream_api_for_stream_consumers | |
| 2710 | 2723 | [API for Stream Implementers]: #stream_api_for_stream_implementers | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -575,6 +575,10 @@ Object.defineProperty(OutgoingMessage.prototype, 'headersSent', { | |||
| 575 | 575 | get: function() { return !!this._header; } | |
| 576 | 576 | }); | |
| 577 | 577 | ||
| 578 | + Object.defineProperty(OutgoingMessage.prototype, 'writableEnded', { | ||
| 579 | + get: function() { return this.finished; } | ||
| 580 | + }); | ||
| 581 | + | ||
| 578 | 582 | ||
| 579 | 583 | const crlf_buf = Buffer.from('\r\n'); | |
| 580 | 584 | OutgoingMessage.prototype.write = function write(chunk, encoding, callback) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,7 +74,7 @@ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', { | |||
| 74 | 74 | // userland will fail | |
| 75 | 75 | enumerable: false, | |
| 76 | 76 | get() { | |
| 77 | - return this._writableState.highWaterMark; | ||
| 77 | + return this._writableState && this._writableState.highWaterMark; | ||
| 78 | 78 | } | |
| 79 | 79 | }); | |
| 80 | 80 | ||
@@ -94,7 +94,7 @@ Object.defineProperty(Duplex.prototype, 'writableLength', { | |||
| 94 | 94 | // userland will fail | |
| 95 | 95 | enumerable: false, | |
| 96 | 96 | get() { | |
| 97 | - return this._writableState.length; | ||
| 97 | + return this._writableState && this._writableState.length; | ||
| 98 | 98 | } | |
| 99 | 99 | }); | |
| 100 | 100 | ||
@@ -104,7 +104,17 @@ Object.defineProperty(Duplex.prototype, 'writableFinished', { | |||
| 104 | 104 | // userland will fail | |
| 105 | 105 | enumerable: false, | |
| 106 | 106 | get() { | |
| 107 | - return this._writableState.finished; | ||
| 107 | + return this._writableState ? this._writableState.finished : false; | ||
| 108 | + } | ||
| 109 | + }); | ||
| 110 | + | ||
| 111 | + Object.defineProperty(Duplex.prototype, 'writableEnded', { | ||
| 112 | + // Making it explicit this property is not enumerable | ||
| 113 | + // because otherwise some prototype manipulation in | ||
| 114 | + // userland will fail | ||
| 115 | + enumerable: false, | ||
| 116 | + get() { | ||
| 117 | + return this._writableState ? this._writableState.ending : false; | ||
| 108 | 118 | } | |
| 109 | 119 | }); | |
| 110 | 120 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -352,13 +352,23 @@ function decodeChunk(state, chunk, encoding) { | |||
| 352 | 352 | return chunk; | |
| 353 | 353 | } | |
| 354 | 354 | ||
| 355 | + Object.defineProperty(Writable.prototype, 'writableEnded', { | ||
| 356 | + // Making it explicit this property is not enumerable | ||
| 357 | + // because otherwise some prototype manipulation in | ||
| 358 | + // userland will fail | ||
| 359 | + enumerable: false, | ||
| 360 | + get: function() { | ||
| 361 | + return this._writableState ? this._writableState.ending : false; | ||
| 362 | + } | ||
| 363 | + }); | ||
| 364 | + | ||
| 355 | 365 | Object.defineProperty(Writable.prototype, 'writableHighWaterMark', { | |
| 356 | 366 | // Making it explicit this property is not enumerable | |
| 357 | 367 | // because otherwise some prototype manipulation in | |
| 358 | 368 | // userland will fail | |
| 359 | 369 | enumerable: false, | |
| 360 | 370 | get: function() { | |
| 361 | - return this._writableState.highWaterMark; | ||
| 371 | + return this._writableState && this._writableState.highWaterMark; | ||
| 362 | 372 | } | |
| 363 | 373 | }); | |
| 364 | 374 | ||
@@ -713,7 +723,7 @@ Object.defineProperty(Writable.prototype, 'writableFinished', { | |||
| 713 | 723 | // userland will fail | |
| 714 | 724 | enumerable: false, | |
| 715 | 725 | get() { | |
| 716 | - return this._writableState.finished; | ||
| 726 | + return this._writableState ? this._writableState.finished : false; | ||
| 717 | 727 | } | |
| 718 | 728 | }); | |
| 719 | 729 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -454,6 +454,11 @@ class Http2ServerResponse extends Stream { | |||
| 454 | 454 | return this.headersSent; | |
| 455 | 455 | } | |
| 456 | 456 | ||
| 457 | + get writableEnded() { | ||
| 458 | + const state = this[kState]; | ||
| 459 | + return state.ending; | ||
| 460 | + } | ||
| 461 | + | ||
| 457 | 462 | get finished() { | |
| 458 | 463 | const stream = this[kStream]; | |
| 459 | 464 | return stream.destroyed || | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,12 +9,14 @@ const http = require('http'); | |||
| 9 | 9 | const server = http.createServer(common.mustCall(function(req, res) { | |
| 10 | 10 | assert.strictEqual(res.writable, true); | |
| 11 | 11 | assert.strictEqual(res.finished, false); | |
| 12 | + assert.strictEqual(res.writableEnded, false); | ||
| 12 | 13 | res.end(); | |
| 13 | 14 | ||
| 14 | 15 | // res.writable is set to false after it has finished sending | |
| 15 | 16 | // Ref: https://github.com/nodejs/node/issues/15029 | |
| 16 | 17 | assert.strictEqual(res.writable, true); | |
| 17 | 18 | assert.strictEqual(res.finished, true); | |
| 19 | + assert.strictEqual(res.writableEnded, true); | ||
| 18 | 20 | ||
| 19 | 21 | server.close(); | |
| 20 | 22 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -150,8 +150,10 @@ const { | |||
| 150 | 150 | // for http1 compatibility | |
| 151 | 151 | const server = createServer(mustCall((request, response) => { | |
| 152 | 152 | strictEqual(response.finished, true); | |
| 153 | + strictEqual(response.writableEnded, false); | ||
| 153 | 154 | response.writeHead(HTTP_STATUS_OK, { foo: 'bar' }); | |
| 154 | 155 | response.end('data', mustCall()); | |
| 156 | + strictEqual(response.writableEnded, true); | ||
| 155 | 157 | })); | |
| 156 | 158 | server.listen(0, mustCall(() => { | |
| 157 | 159 | const { port } = server.address(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,8 +25,10 @@ server.listen(0, common.mustCall(() => { | |||
| 25 | 25 | })); | |
| 26 | 26 | })); | |
| 27 | 27 | assert.strictEqual(response.finished, false); | |
| 28 | + assert.strictEqual(response.writableEnded, false); | ||
| 28 | 29 | response.end(); | |
| 29 | 30 | assert.strictEqual(response.finished, true); | |
| 31 | + assert.strictEqual(response.writableEnded, true); | ||
| 30 | 32 | })); | |
| 31 | 33 | ||
| 32 | 34 | const url = `http://localhost:${port}`; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments