summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-compat-write-early-hints-invalid-argument-value.js
blob: d640f13fae6f5eef4fa7514b4d1956b37bfd08f2 (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
'use strict';

const common = require('../common');
if (!common.hasCrypto) common.skip('missing crypto');

const assert = require('node:assert');
const http2 = require('node:http2');
const debug = require('node:util').debuglog('test');

const testResBody = 'response content';

{
  // Invalid link header value

  const server = http2.createServer();

  server.on('request', common.mustCall((req, res) => {
    debug('Server sending early hints...');
    res.writeEarlyHints({ link: BigInt(100) });

    debug('Server sending full response...');
    res.end(testResBody);
  }));

  server.listen(0);

  server.on('listening', common.mustCall(() => {
    const client = http2.connect(`http://localhost:${server.address().port}`);
    const req = client.request();

    debug('Client sending request...');

    req.on('headers', common.mustNotCall());

    process.on('uncaughtException', (err) => {
      debug(`Caught an exception: ${JSON.stringify(err)}`);
      if (err.name === 'AssertionError') throw err;
      assert.strictEqual(err.code, 'ERR_INVALID_ARG_VALUE');
      process.exit(0);
    });
  }));
}