1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const http2 = require('http2'); 7const assert = require('assert'); 8const path = require('path'); 9 10const { 11 HTTP2_HEADER_CONTENT_TYPE 12} = http2.constants; 13 14const server = http2.createServer(); 15server.on('stream', (stream) => { 16 const file = path.join(process.cwd(), 'not-a-file'); 17 stream.respondWithFile(file, { 18 [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain' 19 }, { 20 onError(err) { 21 common.expectsError({ 22 code: 'ENOENT', 23 name: 'Error', 24 message: `ENOENT: no such file or directory, open '${file}'` 25 })(err); 26 27 stream.respond({ ':status': 404 }); 28 stream.end(); 29 }, 30 statCheck: common.mustNotCall() 31 }); 32}); 33server.listen(0, () => { 34 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'], 404); 40 })); 41 req.on('data', common.mustNotCall()); 42 req.on('end', common.mustCall(() => { 43 client.close(); 44 server.close(); 45 })); 46 req.end(); 47}); 48