11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst http = require('http'); 41cb0ef41Sopenharmony_ciconst stream = require('stream'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci// Verify that when piping a stream to an `OutgoingMessage` (or a type that 71cb0ef41Sopenharmony_ci// inherits from `OutgoingMessage`), if data is emitted after the 81cb0ef41Sopenharmony_ci// `OutgoingMessage` was closed - a `write after end` error is raised 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciclass MyStream extends stream {} 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall(function(req, res) { 131cb0ef41Sopenharmony_ci const myStream = new MyStream(); 141cb0ef41Sopenharmony_ci myStream.pipe(res); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci process.nextTick(common.mustCall(() => { 171cb0ef41Sopenharmony_ci res.end(); 181cb0ef41Sopenharmony_ci myStream.emit('data', 'some data'); 191cb0ef41Sopenharmony_ci res.on('error', common.expectsError({ 201cb0ef41Sopenharmony_ci code: 'ERR_STREAM_WRITE_AFTER_END', 211cb0ef41Sopenharmony_ci name: 'Error' 221cb0ef41Sopenharmony_ci })); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci process.nextTick(common.mustCall(() => server.close())); 251cb0ef41Sopenharmony_ci })); 261cb0ef41Sopenharmony_ci})); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ciserver.listen(0); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciserver.on('listening', common.mustCall(function() { 311cb0ef41Sopenharmony_ci http.request({ 321cb0ef41Sopenharmony_ci port: server.address().port, 331cb0ef41Sopenharmony_ci method: 'GET', 341cb0ef41Sopenharmony_ci path: '/' 351cb0ef41Sopenharmony_ci }).end(); 361cb0ef41Sopenharmony_ci})); 37