• 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
9// Check that pushStream handles being passed wrong arguments
10// in the expected manner
11
12const server = http2.createServer();
13server.on('stream', common.mustCall((stream, headers) => {
14  const port = server.address().port;
15
16  // Must receive a callback (function)
17  assert.throws(
18    () => stream.pushStream({
19      ':scheme': 'http',
20      ':path': '/foobar',
21      ':authority': `localhost:${port}`,
22    }, {}, 'callback'),
23    {
24      code: 'ERR_INVALID_CALLBACK',
25      message: "Callback must be a function. Received 'callback'"
26    }
27  );
28
29  // Must validate headers
30  assert.throws(
31    () => stream.pushStream({ 'connection': 'test' }, {}, () => {}),
32    {
33      code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
34      name: 'TypeError',
35      message: 'HTTP/1 Connection specific headers are forbidden: "connection"'
36    }
37  );
38
39  stream.end('test');
40}));
41
42server.listen(0, common.mustCall(() => {
43  const port = server.address().port;
44  const headers = { ':path': '/' };
45  const client = http2.connect(`http://localhost:${port}`);
46  const req = client.request(headers);
47  req.setEncoding('utf8');
48
49  let data = '';
50  req.on('data', common.mustCall((d) => data += d));
51  req.on('end', common.mustCall(() => {
52    assert.strictEqual(data, 'test');
53    server.close();
54    client.close();
55  }));
56  req.end();
57}));
58