• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6if (common.isWindows)
7  common.skip('no mkfifo on Windows');
8const child_process = require('child_process');
9const path = require('path');
10const fs = require('fs');
11const http2 = require('http2');
12const assert = require('assert');
13
14const tmpdir = require('../common/tmpdir');
15tmpdir.refresh();
16
17const pipeName = path.join(tmpdir.path, 'pipe');
18
19const mkfifo = child_process.spawnSync('mkfifo', [ pipeName ]);
20if (mkfifo.error && mkfifo.error.code === 'ENOENT') {
21  common.skip('missing mkfifo');
22}
23
24process.on('exit', () => fs.unlinkSync(pipeName));
25
26const server = http2.createServer();
27server.on('stream', (stream) => {
28  stream.respondWithFile(pipeName, {
29    'content-type': 'text/plain'
30  }, {
31    onError: common.mustNotCall(),
32    statCheck: common.mustCall()
33  });
34});
35
36server.listen(0, () => {
37  const client = http2.connect(`http://localhost:${server.address().port}`);
38  const req = client.request();
39
40  req.on('response', common.mustCall((headers) => {
41    assert.strictEqual(headers[':status'], 200);
42  }));
43  let body = '';
44  req.setEncoding('utf8');
45  req.on('data', (chunk) => body += chunk);
46  req.on('end', common.mustCall(() => {
47    assert.strictEqual(body, 'Hello, world!\n');
48    client.close();
49    server.close();
50  }));
51  req.end();
52});
53
54fs.open(pipeName, 'w', common.mustCall((err, fd) => {
55  assert.ifError(err);
56  fs.writeSync(fd, 'Hello, world!\n');
57  fs.closeSync(fd);
58}));
59