summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-server-write-after-end.js
blob: a405844cfc9659e3a9f5463653fcc6fd32588d6e (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.mustCall((err) => {
    common.expectsError({
      code: 'ERR_STREAM_WRITE_AFTER_END',
      type: Error
    })(err);
    server.close();
  }));

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

  setImmediate(common.mustCall(() => {
    res.write('world');
  }));
}

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