1'use strict';
2
3const common = require('../common');
4const http = require('http');
5
6const server = http.createServer(handle);
7
8function handle(req, res) {
9  res.on('error', common.mustNotCall());
10
11  res.write('hello');
12  res.end();
13
14  setImmediate(common.mustCall(() => {
15    res.end('world');
16    process.nextTick(() => {
17      server.close();
18    });
19    res.write('world', common.mustCall((err) => {
20      common.expectsError({
21        code: 'ERR_STREAM_WRITE_AFTER_END',
22        name: 'Error'
23      })(err);
24      server.close();
25    }));
26  }));
27}
28
29server.listen(0, common.mustCall(() => {
30  http.get(`http://localhost:${server.address().port}`);
31}));
32