summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-server-push-disabled.js
blob: 33f8ed7c65e2f1d4249164386ede0670eec9b874 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Flags: --expose-http2
'use strict';

const common = require('../common');
const assert = require('assert');
const http2 = require('http2');

const server = http2.createServer();

server.on('session', common.mustCall((session) => {
  // Verify that the settings disabling push is received
  session.on('remoteSettings', common.mustCall((settings) => {
    assert.strictEqual(settings.enablePush, false);
  }));
}));

server.on('stream', common.mustCall((stream) => {

  // The client has disabled push streams, so pushAllowed must be false,
  // and pushStream() must throw.
  assert.strictEqual(stream.pushAllowed, false);

  assert.throws(() => {
    stream.pushStream({
      ':scheme': 'http',
      ':path': '/foobar',
      ':authority': `localhost:${server.address().port}`,
    }, common.mustNotCall());
  }, common.expectsError({
    code: 'ERR_HTTP2_PUSH_DISABLED',
    type: Error
  }));

  stream.respond({ ':status': 200 });
  stream.end('test');
}));

server.listen(0, common.mustCall(() => {
  const options = { settings: { enablePush: false } };
  const client = http2.connect(`http://localhost:${server.address().port}`,
                               options);
  const req = client.request({ ':path': '/' });

  // Because push stream sre disabled, this must not be called.
  client.on('stream', common.mustNotCall());

  req.resume();
  req.on('end', common.mustCall(() => {
    server.close();
    client.destroy();
  }));
  req.end();
}));