• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const assert = require('assert');
8const { createServer, constants, connect } = require('http2');
9
10const server = createServer();
11
12server.on('stream', (stream, headers) => {
13  stream.respond(undefined, { waitForTrailers: true });
14
15  stream.on('data', common.mustNotCall());
16
17  stream.on('wantTrailers', common.mustCall(() => {
18    // Trigger a frame error by sending a trailer that is too large
19    stream.sendTrailers({ 'test-trailer': 'X'.repeat(64 * 1024) });
20  }));
21
22  stream.on('frameError', common.mustCall((frameType, errorCode) => {
23    assert.strictEqual(errorCode, constants.NGHTTP2_FRAME_SIZE_ERROR);
24  }));
25
26  stream.on('error', common.expectsError({
27    code: 'ERR_HTTP2_STREAM_ERROR',
28  }));
29
30  stream.on('close', common.mustCall());
31
32  stream.end();
33});
34
35server.listen(0, () => {
36  const clientSession = connect(`http://localhost:${server.address().port}`);
37
38  clientSession.on('frameError', common.mustNotCall());
39  clientSession.on('close', common.mustCall(() => {
40    server.close();
41  }));
42
43  const clientStream = clientSession.request();
44
45  clientStream.on('close', common.mustCall());
46  // These events mustn't be called once the frame size error is from the server
47  clientStream.on('frameError', common.mustNotCall());
48  clientStream.on('error', common.mustNotCall());
49
50  clientStream.end();
51});
52