0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-client-incomingmessage-destroy.js
Robert Nagy d385106302
http: make OutgoingMessage more streamlike
Implement missing getters error & closed. Add support for
proper "writable" check through `isWritable` helper.

We cannot fix the `OutgoingMessage.writable` property as that
would break the ecosystem.

PR-URL: https://github.com/nodejs/node/pull/45672
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-12-02 10:40:44 +01:00

33 lines
798 B
JavaScript

'use strict';
const common = require('../common');
const { createServer, get } = require('http');
const assert = require('assert');
const server = createServer(common.mustCall((req, res) => {
res.writeHead(200);
res.write('Part of res.');
}));
function onUncaught(error) {
assert.strictEqual(error.message, 'Destroy test');
server.close();
}
process.on('uncaughtException', common.mustCall(onUncaught));
server.listen(0, () => {
get({
port: server.address().port
}, common.mustCall((res) => {
const err = new Error('Destroy test');
assert.strictEqual(res.errored, null);
res.destroy(err);
assert.strictEqual(res.closed, false);
assert.strictEqual(res.errored, err);
res.on('close', () => {
assert.strictEqual(res.closed, true);
});
}));
});