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 http2 = require('http2');
71cb0ef41Sopenharmony_ciconst fs = require('fs');
81cb0ef41Sopenharmony_ciconst makeDuplexPair = require('../common/duplexpair');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci{
111cb0ef41Sopenharmony_ci  const server = http2.createServer();
121cb0ef41Sopenharmony_ci  server.on('stream', common.mustCall((stream, headers) => {
131cb0ef41Sopenharmony_ci    stream.respondWithFile(__filename);
141cb0ef41Sopenharmony_ci  }));
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  const { clientSide, serverSide } = makeDuplexPair();
171cb0ef41Sopenharmony_ci  server.emit('connection', serverSide);
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  const client = http2.connect('http://localhost:80', {
201cb0ef41Sopenharmony_ci    createConnection: common.mustCall(() => clientSide)
211cb0ef41Sopenharmony_ci  });
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  const req = client.request();
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  req.on('response', common.mustCall((headers) => {
261cb0ef41Sopenharmony_ci    assert.strictEqual(headers[':status'], 200);
271cb0ef41Sopenharmony_ci  }));
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  req.setEncoding('utf8');
301cb0ef41Sopenharmony_ci  let data = '';
311cb0ef41Sopenharmony_ci  req.on('data', (chunk) => data += chunk);
321cb0ef41Sopenharmony_ci  req.on('end', common.mustCall(() => {
331cb0ef41Sopenharmony_ci    assert.strictEqual(data, fs.readFileSync(__filename, 'utf8'));
341cb0ef41Sopenharmony_ci    clientSide.destroy();
351cb0ef41Sopenharmony_ci    clientSide.end();
361cb0ef41Sopenharmony_ci  }));
371cb0ef41Sopenharmony_ci  req.end();
381cb0ef41Sopenharmony_ci}
39