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 offset: 10, 32 onError(err) { 33 common.expectsError({ 34 code: 'ERR_HTTP2_SEND_FILE_NOSEEK', 35 name: 'Error', 36 message: 'Offset or length can only be specified for regular files' 37 })(err); 38 39 stream.respond({ ':status': 404 }); 40 stream.end(); 41 }, 42 statCheck: common.mustNotCall() 43 }); 44}); 45server.listen(0, () => { 46 47 const client = http2.connect(`http://localhost:${server.address().port}`); 48 const req = client.request(); 49 50 req.on('response', common.mustCall((headers) => { 51 assert.strictEqual(headers[':status'], 404); 52 })); 53 req.on('data', common.mustNotCall()); 54 req.on('end', common.mustCall(() => { 55 client.close(); 56 server.close(); 57 })); 58 req.end(); 59}); 60 61fs.writeFile(pipeName, 'Hello, world!\n', common.mustCall()); 62