11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto)
41cb0ef41Sopenharmony_ci  common.skip('missing crypto');
51cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
61cb0ef41Sopenharmony_ciconst http2 = require('http2');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// This test will result in a crash due to a missed CHECK in C++ or
91cb0ef41Sopenharmony_ci// a straight-up segfault if the C++ doesn't send RST_STREAM through
101cb0ef41Sopenharmony_ci// properly when calling destroy.
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst content = Buffer.alloc(60000, 0x44);
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst server = http2.createSecureServer({
151cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
161cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem')
171cb0ef41Sopenharmony_ci});
181cb0ef41Sopenharmony_ciserver.on('stream', common.mustCall((stream) => {
191cb0ef41Sopenharmony_ci  stream.respond({
201cb0ef41Sopenharmony_ci    'Content-Type': 'application/octet-stream',
211cb0ef41Sopenharmony_ci    'Content-Length': (content.length.toString() * 2),
221cb0ef41Sopenharmony_ci    'Vary': 'Accept-Encoding'
231cb0ef41Sopenharmony_ci  }, { waitForTrailers: true });
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  stream.write(content);
261cb0ef41Sopenharmony_ci  stream.destroy();
271cb0ef41Sopenharmony_ci}));
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
301cb0ef41Sopenharmony_ci  const client = http2.connect(`https://localhost:${server.address().port}`,
311cb0ef41Sopenharmony_ci                               { rejectUnauthorized: false });
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  const req = client.request({ ':path': '/' });
341cb0ef41Sopenharmony_ci  req.end();
351cb0ef41Sopenharmony_ci  req.resume(); // Otherwise close won't be emitted if there's pending data.
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  req.on('close', common.mustCall(() => {
381cb0ef41Sopenharmony_ci    client.close();
391cb0ef41Sopenharmony_ci    server.close();
401cb0ef41Sopenharmony_ci  }));
411cb0ef41Sopenharmony_ci}));
42