1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const http = require('http'); 5 6const onWriteAfterEndError = common.mustCall((err) => { 7 assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END'); 8}, 2); 9 10const server = http.createServer(common.mustCall(function(req, res) { 11 res.end('testing ended state', common.mustCall()); 12 assert.strictEqual(res.writableCorked, 0); 13 res.end(common.mustCall((err) => { 14 assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED'); 15 })); 16 assert.strictEqual(res.writableCorked, 0); 17 res.end('end', onWriteAfterEndError); 18 assert.strictEqual(res.writableCorked, 0); 19 res.on('error', onWriteAfterEndError); 20 res.on('finish', common.mustCall(() => { 21 res.end(common.mustCall((err) => { 22 assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED'); 23 server.close(); 24 })); 25 })); 26})); 27 28server.listen(0); 29 30server.on('listening', common.mustCall(function() { 31 http 32 .request({ 33 port: server.address().port, 34 method: 'GET', 35 path: '/' 36 }) 37 .end(); 38})); 39