11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ciconst http2 = require('http2');
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst {
91cb0ef41Sopenharmony_ci  DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE,
101cb0ef41Sopenharmony_ci  NGHTTP2_CANCEL,
111cb0ef41Sopenharmony_ci} = http2.constants;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst headerSize = DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE;
141cb0ef41Sopenharmony_ciconst timeout = common.platformTimeout(2_000);
151cb0ef41Sopenharmony_ciconst timer = setTimeout(() => assert.fail(`http2 client timedout
161cb0ef41Sopenharmony_ciwhen server can not manage to send a header of size ${headerSize}`), timeout);
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciconst server = http2.createServer((req, res) => {
191cb0ef41Sopenharmony_ci  res.setHeader('foobar', 'a'.repeat(DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE));
201cb0ef41Sopenharmony_ci  res.end();
211cb0ef41Sopenharmony_ci});
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
241cb0ef41Sopenharmony_ci  const clientSession = http2.connect(`http://localhost:${server.address().port}`);
251cb0ef41Sopenharmony_ci  clientSession.on('close', common.mustCall());
261cb0ef41Sopenharmony_ci  clientSession.on('remoteSettings', send);
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  function send() {
291cb0ef41Sopenharmony_ci    const stream = clientSession.request({ ':path': '/' });
301cb0ef41Sopenharmony_ci    stream.on('close', common.mustCall(() => {
311cb0ef41Sopenharmony_ci      assert.strictEqual(stream.rstCode, NGHTTP2_CANCEL);
321cb0ef41Sopenharmony_ci      clearTimeout(timer);
331cb0ef41Sopenharmony_ci      server.close();
341cb0ef41Sopenharmony_ci    }));
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci    stream.end();
371cb0ef41Sopenharmony_ci  }
381cb0ef41Sopenharmony_ci}));
39