1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const http2 = require('http2'); 7const assert = require('assert'); 8 9const server = http2.createServer(); 10server.on('stream', (stream) => { 11 stream.respondWithFile(process.cwd(), { 12 'content-type': 'text/plain' 13 }, { 14 onError(err) { 15 common.expectsError({ 16 code: 'ERR_HTTP2_SEND_FILE', 17 name: 'Error', 18 message: 'Directories cannot be sent' 19 })(err); 20 21 stream.respond({ ':status': 404 }); 22 stream.end(); 23 }, 24 statCheck: common.mustNotCall() 25 }); 26}); 27server.listen(0, () => { 28 29 const client = http2.connect(`http://localhost:${server.address().port}`); 30 const req = client.request(); 31 32 req.on('response', common.mustCall((headers) => { 33 assert.strictEqual(headers[':status'], 404); 34 })); 35 req.on('data', common.mustNotCall()); 36 req.on('end', common.mustCall(() => { 37 client.close(); 38 server.close(); 39 })); 40 req.end(); 41}); 42