11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst { createServer, constants, connect } = require('http2'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst server = createServer(); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciserver.on('stream', (stream, headers) => { 131cb0ef41Sopenharmony_ci stream.respond(undefined, { waitForTrailers: true }); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci stream.on('data', common.mustNotCall()); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci stream.on('wantTrailers', common.mustCall(() => { 181cb0ef41Sopenharmony_ci // Trigger a frame error by sending a trailer that is too large 191cb0ef41Sopenharmony_ci stream.sendTrailers({ 'test-trailer': 'X'.repeat(64 * 1024) }); 201cb0ef41Sopenharmony_ci })); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci stream.on('frameError', common.mustCall((frameType, errorCode) => { 231cb0ef41Sopenharmony_ci assert.strictEqual(errorCode, constants.NGHTTP2_FRAME_SIZE_ERROR); 241cb0ef41Sopenharmony_ci })); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci stream.on('error', common.expectsError({ 271cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_STREAM_ERROR', 281cb0ef41Sopenharmony_ci })); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci stream.on('close', common.mustCall()); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci stream.end(); 331cb0ef41Sopenharmony_ci}); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciserver.listen(0, () => { 361cb0ef41Sopenharmony_ci const clientSession = connect(`http://localhost:${server.address().port}`); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci clientSession.on('frameError', common.mustNotCall()); 391cb0ef41Sopenharmony_ci clientSession.on('close', common.mustCall(() => { 401cb0ef41Sopenharmony_ci server.close(); 411cb0ef41Sopenharmony_ci })); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci const clientStream = clientSession.request(); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci clientStream.on('close', common.mustCall()); 461cb0ef41Sopenharmony_ci // These events mustn't be called once the frame size error is from the server 471cb0ef41Sopenharmony_ci clientStream.on('frameError', common.mustNotCall()); 481cb0ef41Sopenharmony_ci clientStream.on('error', common.mustNotCall()); 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci clientStream.end(); 511cb0ef41Sopenharmony_ci}); 52