summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-compat-serverresponse-close.js
blob: 71079f425c97fc596b34e0b5861bbd0e6cea84fd (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
30
31
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');
const h2 = require('http2');

// Server request and response should receive close event
// if the connection was terminated before response.end
// could be called or flushed

const server = h2.createServer(common.mustCall((req, res) => {
  res.writeHead(200);
  res.write('a');

  req.on('close', common.mustCall());
  res.on('close', common.mustCall());
  req.on('error', common.mustNotCall());
}));
server.listen(0);

server.on('listening', () => {
  const url = `http://localhost:${server.address().port}`;
  const client = h2.connect(url, common.mustCall(() => {
    const request = client.request();
    request.on('data', common.mustCall(function(chunk) {
      client.destroy();
      server.close();
    }));
  }));
});