• 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 server = http2.createServer();
10
11server.on('session', common.mustCall((session) => {
12  // Verify that the settings disabling push is received
13  session.on('remoteSettings', common.mustCall((settings) => {
14    assert.strictEqual(settings.enablePush, false);
15  }));
16}));
17
18server.on('stream', common.mustCall((stream) => {
19
20  // The client has disabled push streams, so pushAllowed must be false,
21  // and pushStream() must throw.
22  assert.strictEqual(stream.pushAllowed, false);
23
24  assert.throws(() => {
25    stream.pushStream({
26      ':scheme': 'http',
27      ':path': '/foobar',
28      ':authority': `localhost:${server.address().port}`,
29    }, common.mustNotCall());
30  }, {
31    code: 'ERR_HTTP2_PUSH_DISABLED',
32    name: 'Error'
33  });
34
35  stream.respond({ ':status': 200 });
36  stream.end('test');
37}));
38
39server.listen(0, common.mustCall(() => {
40  const options = { settings: { enablePush: false } };
41  const client = http2.connect(`http://localhost:${server.address().port}`,
42                               options);
43  const req = client.request({ ':path': '/' });
44
45  // Because push streams are disabled, this must not be called.
46  client.on('stream', common.mustNotCall());
47
48  req.resume();
49  req.on('end', common.mustCall(() => {
50    server.close();
51    client.close();
52  }));
53  req.end();
54}));
55