|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +if (!common.hasCrypto) |
| 5 | + common.skip('missing crypto'); |
| 6 | +if (common.isWindows) |
| 7 | + common.skip('no mkfifo on Windows'); |
| 8 | +const child_process = require('child_process'); |
| 9 | +const path = require('path'); |
| 10 | +const fs = require('fs'); |
| 11 | +const http2 = require('http2'); |
| 12 | +const assert = require('assert'); |
| 13 | + |
| 14 | +const tmpdir = require('../common/tmpdir'); |
| 15 | +tmpdir.refresh(); |
| 16 | + |
| 17 | +const pipeName = path.join(tmpdir.path, 'pipe'); |
| 18 | + |
| 19 | +const mkfifo = child_process.spawnSync('mkfifo', [ pipeName ]); |
| 20 | +if (mkfifo.error && mkfifo.error.code === 'ENOENT') { |
| 21 | + common.skip('missing mkfifo'); |
| 22 | +} |
| 23 | + |
| 24 | +process.on('exit', () => fs.unlinkSync(pipeName)); |
| 25 | + |
| 26 | +const server = http2.createServer(); |
| 27 | +server.on('stream', (stream) => { |
| 28 | + stream.respondWithFile(pipeName, { |
| 29 | + 'content-type': 'text/plain' |
| 30 | + }, { |
| 31 | + onError: common.mustNotCall(), |
| 32 | + statCheck: common.mustCall() |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +server.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 | + |
| 54 | +fs.open(pipeName, 'w', common.mustCall((err, fd) => { |
| 55 | + assert.ifError(err); |
| 56 | + fs.writeSync(fd, 'Hello, world!\n'); |
| 57 | + fs.closeSync(fd); |
| 58 | +})); |
0 commit comments