11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciif (!common.hasCrypto)
61cb0ef41Sopenharmony_ci  common.skip('missing crypto');
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst http2 = require('http2');
91cb0ef41Sopenharmony_ciconst util = require('util');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst server = http2.createServer();
121cb0ef41Sopenharmony_ciserver.on('stream', common.mustCall((stream) => {
131cb0ef41Sopenharmony_ci  stream.respond();
141cb0ef41Sopenharmony_ci  stream.end('ok');
151cb0ef41Sopenharmony_ci}));
161cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
171cb0ef41Sopenharmony_ci  const connect = util.promisify(http2.connect);
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  connect(`http://localhost:${server.address().port}`)
201cb0ef41Sopenharmony_ci    .then(common.mustCall((client) => {
211cb0ef41Sopenharmony_ci      assert(client);
221cb0ef41Sopenharmony_ci      const req = client.request();
231cb0ef41Sopenharmony_ci      let data = '';
241cb0ef41Sopenharmony_ci      req.setEncoding('utf8');
251cb0ef41Sopenharmony_ci      req.on('data', (chunk) => data += chunk);
261cb0ef41Sopenharmony_ci      req.on('end', common.mustCall(() => {
271cb0ef41Sopenharmony_ci        assert.strictEqual(data, 'ok');
281cb0ef41Sopenharmony_ci        client.close();
291cb0ef41Sopenharmony_ci        server.close();
301cb0ef41Sopenharmony_ci      }));
311cb0ef41Sopenharmony_ci    }));
321cb0ef41Sopenharmony_ci}));
33