mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
6f613d8abb
This is work towards resolving the response.finished confusion and future deprecation. Note that implementation-wise, streams have both an ending and ended state. However, in this case (in order to avoid confusion in user space) writableEnded is equal to writable.ending. The ending vs ended situation is internal state required for internal stream logic. PR-URL: https://github.com/nodejs/node/pull/28934 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
// Verify that after calling end() on an `OutgoingMessage` (or a type that
|
|
// inherits from `OutgoingMessage`), its `writable` property is not set to false
|
|
|
|
const server = http.createServer(common.mustCall(function(req, res) {
|
|
assert.strictEqual(res.writable, true);
|
|
assert.strictEqual(res.finished, false);
|
|
assert.strictEqual(res.writableEnded, false);
|
|
res.end();
|
|
|
|
// res.writable is set to false after it has finished sending
|
|
// Ref: https://github.com/nodejs/node/issues/15029
|
|
assert.strictEqual(res.writable, true);
|
|
assert.strictEqual(res.finished, true);
|
|
assert.strictEqual(res.writableEnded, true);
|
|
|
|
server.close();
|
|
}));
|
|
|
|
server.listen(0);
|
|
|
|
server.on('listening', common.mustCall(function() {
|
|
const clientRequest = http.request({
|
|
port: server.address().port,
|
|
method: 'GET',
|
|
path: '/'
|
|
});
|
|
|
|
assert.strictEqual(clientRequest.writable, true);
|
|
clientRequest.end();
|
|
|
|
// Writable is still true when close
|
|
// THIS IS LEGACY, we cannot change it
|
|
// unless we break error detection
|
|
assert.strictEqual(clientRequest.writable, true);
|
|
}));
|