• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6const h2 = require('http2');
7
8// Server request and response should receive close event
9// if the connection was terminated before response.end
10// could be called or flushed
11
12const server = h2.createServer(common.mustCall((req, res) => {
13  res.writeHead(200);
14  res.write('a');
15
16  req.on('close', common.mustCall());
17  res.on('close', common.mustCall());
18  req.on('error', common.mustNotCall());
19}));
20server.listen(0);
21
22server.on('listening', () => {
23  const url = `http://localhost:${server.address().port}`;
24  const client = h2.connect(url, common.mustCall(() => {
25    const request = client.request();
26    request.on('data', common.mustCall(function(chunk) {
27      client.destroy();
28      server.close();
29    }));
30  }));
31});
32