• 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 h2 = require('http2');
8
9const server = h2.createServer();
10
11// We use the lower-level API here
12server.on('stream', common.mustCall((stream) => {
13  stream.setTimeout(1, common.mustCall(() => {
14    stream.respond({ ':status': 200 });
15    stream.end('hello world');
16  }));
17
18  // Check that expected errors are thrown with wrong args
19  assert.throws(
20    () => stream.setTimeout('100'),
21    {
22      code: 'ERR_INVALID_ARG_TYPE',
23      name: 'TypeError',
24      message:
25        'The "msecs" argument must be of type number. Received type string' +
26        " ('100')"
27    }
28  );
29  assert.throws(
30    () => stream.setTimeout(0, Symbol('test')),
31    {
32      code: 'ERR_INVALID_CALLBACK',
33      name: 'TypeError',
34      message: 'Callback must be a function. Received Symbol(test)'
35    }
36  );
37  assert.throws(
38    () => stream.setTimeout(100, {}),
39    {
40      code: 'ERR_INVALID_CALLBACK',
41      name: 'TypeError',
42      message: 'Callback must be a function. Received {}'
43    }
44  );
45}));
46server.listen(0);
47
48server.on('listening', common.mustCall(() => {
49  const client = h2.connect(`http://localhost:${server.address().port}`);
50  client.setTimeout(1, common.mustCall(() => {
51    const req = client.request({ ':path': '/' });
52    req.setTimeout(1, common.mustCall(() => {
53      req.on('response', common.mustCall());
54      req.resume();
55      req.on('end', common.mustCall(() => {
56        server.close();
57        client.close();
58      }));
59      req.end();
60    }));
61  }));
62}));
63