mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 16:22:29 +00:00

Setting writable = false in IncomingMessage.end made some errors being swallowed in some very popular OSS libraries that we must support. This commit add some of those use cases to the tests, so we avoid further regressions. We should reevaluate how to set writable = false in IncomingMessage in a way that does not break the ecosystem. See: https://github.com/nodejs/node/pull/14024 Fixes: https://github.com/nodejs/node/issues/15029 PR-URL: https://github.com/nodejs/node/pull/15404 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const http = require('http');
|
|
const assert = require('assert');
|
|
const util = require('util');
|
|
const stream = require('stream');
|
|
|
|
// Verify that when piping a stream to an `OutgoingMessage` (or a type that
|
|
// inherits from `OutgoingMessage`), if data is emitted after the
|
|
// `OutgoingMessage` was closed - a `write after end` error is raised
|
|
|
|
function MyStream() {
|
|
stream.call(this);
|
|
}
|
|
util.inherits(MyStream, stream);
|
|
|
|
const server = http.createServer(common.mustCall(function(req, res) {
|
|
const myStream = new MyStream();
|
|
myStream.pipe(res);
|
|
|
|
process.nextTick(common.mustCall(() => {
|
|
res.end();
|
|
myStream.emit('data', 'some data');
|
|
res.on('error', common.mustCall(function(err) {
|
|
assert.strictEqual(err.message, 'write after end');
|
|
}));
|
|
|
|
process.nextTick(common.mustCall(() => server.close()));
|
|
}));
|
|
}));
|
|
|
|
server.listen(0);
|
|
|
|
server.on('listening', common.mustCall(function() {
|
|
http.request({
|
|
port: server.address().port,
|
|
method: 'GET',
|
|
path: '/'
|
|
}).end();
|
|
}));
|