• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6const assert = require('assert');
7const http2 = require('http2');
8
9const msecs = common.platformTimeout(1);
10const server = http2.createServer();
11
12server.on('request', (req, res) => {
13  const request = req.setTimeout(msecs, common.mustCall(() => {
14    res.end();
15  }));
16  assert.strictEqual(request, req);
17  req.on('timeout', common.mustCall());
18  res.on('finish', common.mustCall(() => {
19    req.setTimeout(msecs, common.mustNotCall());
20    process.nextTick(() => {
21      req.setTimeout(msecs, common.mustNotCall());
22      server.close();
23    });
24  }));
25});
26
27server.listen(0, common.mustCall(() => {
28  const port = server.address().port;
29  const client = http2.connect(`http://localhost:${port}`);
30  const req = client.request({
31    ':path': '/',
32    ':method': 'GET',
33    ':scheme': 'http',
34    ':authority': `localhost:${port}`
35  });
36  req.on('end', common.mustCall(() => {
37    client.close();
38  }));
39  req.resume();
40  req.end();
41}));
42