mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 18:37:06 +00:00
http: add response.writableFinished
response.writableFinished is true if all data has been flushed to the underlying system. PR-URL: https://github.com/nodejs/node/pull/28681 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
caee9106ac
commit
06d0abea0d
@ -1464,6 +1464,15 @@ Returns `true` if the entire data was flushed successfully to the kernel
|
|||||||
buffer. Returns `false` if all or part of the data was queued in user memory.
|
buffer. Returns `false` if all or part of the data was queued in user memory.
|
||||||
`'drain'` will be emitted when the buffer is free again.
|
`'drain'` will be emitted when the buffer is free again.
|
||||||
|
|
||||||
|
### response.writableFinished
|
||||||
|
<!-- YAML
|
||||||
|
added: REPLACEME
|
||||||
|
-->
|
||||||
|
|
||||||
|
* {boolean}
|
||||||
|
|
||||||
|
Is `true` if all data has been flushed to the underlying system.
|
||||||
|
|
||||||
### response.writeContinue()
|
### response.writeContinue()
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.3.0
|
added: v0.3.0
|
||||||
|
@ -109,6 +109,15 @@ function OutgoingMessage() {
|
|||||||
Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
|
Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
|
||||||
Object.setPrototypeOf(OutgoingMessage, Stream);
|
Object.setPrototypeOf(OutgoingMessage, Stream);
|
||||||
|
|
||||||
|
Object.defineProperty(OutgoingMessage.prototype, 'writableFinished', {
|
||||||
|
get: function() {
|
||||||
|
return (
|
||||||
|
this.finished &&
|
||||||
|
this.outputSize === 0 &&
|
||||||
|
(!this.socket || this.socket.writableLength === 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Object.defineProperty(OutgoingMessage.prototype, '_headers', {
|
Object.defineProperty(OutgoingMessage.prototype, '_headers', {
|
||||||
get: internalUtil.deprecate(function() {
|
get: internalUtil.deprecate(function() {
|
||||||
|
32
test/parallel/test-http-outgoing-writableFinished.js
Normal file
32
test/parallel/test-http-outgoing-writableFinished.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const http = require('http');
|
||||||
|
|
||||||
|
const server = http.createServer(common.mustCall(function(req, res) {
|
||||||
|
assert.strictEqual(res.writableFinished, false);
|
||||||
|
res
|
||||||
|
.on('finish', common.mustCall(() => {
|
||||||
|
assert.strictEqual(res.writableFinished, true);
|
||||||
|
server.close();
|
||||||
|
}))
|
||||||
|
.end();
|
||||||
|
}));
|
||||||
|
|
||||||
|
server.listen(0);
|
||||||
|
|
||||||
|
server.on('listening', common.mustCall(function() {
|
||||||
|
const clientRequest = http.request({
|
||||||
|
port: server.address().port,
|
||||||
|
method: 'GET',
|
||||||
|
path: '/'
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(clientRequest.writableFinished, false);
|
||||||
|
clientRequest
|
||||||
|
.on('finish', common.mustCall(() => {
|
||||||
|
assert.strictEqual(clientRequest.writableFinished, true);
|
||||||
|
}))
|
||||||
|
.end();
|
||||||
|
assert.strictEqual(clientRequest.writableFinished, false);
|
||||||
|
}));
|
Loading…
Reference in New Issue
Block a user