summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-goaway-opaquedata.js
blob: af1ce27dd4a8fa65107d9e6260f4ba8812827755 (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
'use strict';

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

const server = http2.createServer();
const data = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);

server.on('stream', common.mustCall((stream) => {
  stream.session.shutdown({
    errorCode: 1,
    opaqueData: data
  });
  stream.end();
  stream.on('error', common.mustCall(common.expectsError({
    code: 'ERR_HTTP2_STREAM_ERROR',
    type: Error,
    message: 'Stream closed with error code 7'
  })));
}));

server.listen(0, () => {

  const client = http2.connect(`http://localhost:${server.address().port}`);
  client.on('goaway', common.mustCall((code, lastStreamID, buf) => {
    assert.deepStrictEqual(code, 1);
    assert.deepStrictEqual(lastStreamID, 0);
    assert.deepStrictEqual(data, buf);
    server.close();
  }));
  const req = client.request({ ':path': '/' });
  req.resume();
  req.on('end', common.mustCall());
  req.end();

});