11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst http2 = require('http2');
91cb0ef41Sopenharmony_ciconst fs = require('fs');
101cb0ef41Sopenharmony_ciconst net = require('net');
111cb0ef41Sopenharmony_ciconst path = require('path');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci// HTTP/2 servers can listen on a named pipe.
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
161cb0ef41Sopenharmony_citmpdir.refresh();
171cb0ef41Sopenharmony_ciconst loc = fixtures.path('person-large.jpg');
181cb0ef41Sopenharmony_ciconst fn = path.join(tmpdir.path, 'person-large.jpg');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciconst server = http2.createServer();
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciserver.on('stream', common.mustCall((stream) => {
231cb0ef41Sopenharmony_ci  const dest = stream.pipe(fs.createWriteStream(fn));
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  stream.on('end', common.mustCall(() => {
261cb0ef41Sopenharmony_ci    stream.respond();
271cb0ef41Sopenharmony_ci    stream.end();
281cb0ef41Sopenharmony_ci  }));
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  dest.on('finish', common.mustCall(() => {
311cb0ef41Sopenharmony_ci    assert.strictEqual(fs.readFileSync(fn).length,
321cb0ef41Sopenharmony_ci                       fs.readFileSync(loc).length);
331cb0ef41Sopenharmony_ci  }));
341cb0ef41Sopenharmony_ci}));
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ciserver.listen(common.PIPE, common.mustCall(() => {
371cb0ef41Sopenharmony_ci  const client = http2.connect('http://localhost', {
381cb0ef41Sopenharmony_ci    createConnection(url) {
391cb0ef41Sopenharmony_ci      return net.connect(server.address());
401cb0ef41Sopenharmony_ci    }
411cb0ef41Sopenharmony_ci  });
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  const req = client.request({ ':method': 'POST' });
441cb0ef41Sopenharmony_ci  req.on('response', common.mustCall());
451cb0ef41Sopenharmony_ci  req.resume();
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  req.on('close', common.mustCall(() => {
481cb0ef41Sopenharmony_ci    server.close();
491cb0ef41Sopenharmony_ci    client.close();
501cb0ef41Sopenharmony_ci  }));
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci  const str = fs.createReadStream(loc);
531cb0ef41Sopenharmony_ci  str.on('end', common.mustCall());
541cb0ef41Sopenharmony_ci  str.pipe(req);
551cb0ef41Sopenharmony_ci}));
56