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
24const server = http2.createServer();
25server.on('stream', (stream) => {
26  stream.respondWithFile(pipeName, {
27    'content-type': 'text/plain'
28  }, {
29    onError: common.mustNotCall(),
30    statCheck: common.mustCall()
31  });
32});
33
34server.listen(0, () => {
35  const client = http2.connect(`http://localhost:${server.address().port}`);
36  const req = client.request();
37
38  req.on('response', common.mustCall((headers) => {
39    assert.strictEqual(headers[':status'], 200);
40  }));
41  let body = '';
42  req.setEncoding('utf8');
43  req.on('data', (chunk) => body += chunk);
44  req.on('end', common.mustCall(() => {
45    assert.strictEqual(body, 'Hello, world!\n');
46    client.close();
47    server.close();
48  }));
49  req.end();
50});
51
52fs.open(pipeName, 'w', common.mustSucceed((fd) => {
53  fs.writeSync(fd, 'Hello, world!\n');
54  fs.closeSync(fd);
55}));
56