11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto)
41cb0ef41Sopenharmony_ci  common.skip('missing crypto');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
71cb0ef41Sopenharmony_ciconst http2 = require('http2');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst content = Buffer.alloc(1e5, 0x44);
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst server = http2.createSecureServer({
121cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
131cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem')
141cb0ef41Sopenharmony_ci});
151cb0ef41Sopenharmony_ciserver.on('stream', common.mustCall((stream) => {
161cb0ef41Sopenharmony_ci  stream.respond({
171cb0ef41Sopenharmony_ci    'Content-Type': 'application/octet-stream',
181cb0ef41Sopenharmony_ci    'Content-Length': (content.length.toString() * 2),
191cb0ef41Sopenharmony_ci    'Vary': 'Accept-Encoding'
201cb0ef41Sopenharmony_ci  });
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  stream.write(content);
231cb0ef41Sopenharmony_ci  stream.write(content);
241cb0ef41Sopenharmony_ci  stream.end();
251cb0ef41Sopenharmony_ci  stream.close();
261cb0ef41Sopenharmony_ci}));
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
291cb0ef41Sopenharmony_ci  const client = http2.connect(`https://localhost:${server.address().port}`,
301cb0ef41Sopenharmony_ci                               { rejectUnauthorized: false });
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  const req = client.request({ ':path': '/' });
331cb0ef41Sopenharmony_ci  req.end();
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  let receivedBufferLength = 0;
361cb0ef41Sopenharmony_ci  req.on('data', common.mustCallAtLeast((buf) => {
371cb0ef41Sopenharmony_ci    receivedBufferLength += buf.length;
381cb0ef41Sopenharmony_ci  }, 1));
391cb0ef41Sopenharmony_ci  req.on('close', common.mustCall(() => {
401cb0ef41Sopenharmony_ci    assert.strictEqual(receivedBufferLength, content.length * 2);
411cb0ef41Sopenharmony_ci    client.close();
421cb0ef41Sopenharmony_ci    server.close();
431cb0ef41Sopenharmony_ci  }));
441cb0ef41Sopenharmony_ci}));
45