summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-server-write-after-end.js
blob: ba2877131227aa377d9bf742b55a85575a4467bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';

const common = require('../common');
const http = require('http');

// Fix for https://github.com/nodejs/node/issues/14368

const server = http.createServer(handle);

function handle(req, res) {
  res.on('error', common.mustNotCall());

  res.write('hello');
  res.end();

  setImmediate(common.mustCall(() => {
    res.write('world', common.mustCall((err) => {
      common.expectsError({
        code: 'ERR_STREAM_WRITE_AFTER_END',
        name: 'Error'
      })(err);
      server.close();
    }));
  }));
}

server.listen(0, common.mustCall(() => {
  http.get(`http://localhost:${server.address().port}`);
}));