1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5const assert = require('assert'); 6const h2 = require('http2'); 7 8// Errors should not be reported both in Http2ServerRequest 9// and Http2ServerResponse 10 11{ 12 let expected = null; 13 14 const server = h2.createServer(); 15 16 server.on('stream', common.mustCall(function(stream) { 17 stream.on('error', common.mustCall(function(err) { 18 assert.strictEqual(err, expected); 19 })); 20 21 stream.resume(); 22 stream.write('hello'); 23 24 expected = new Error('kaboom'); 25 stream.destroy(expected); 26 server.close(); 27 })); 28 29 server.listen(0, common.mustCall(function() { 30 const port = server.address().port; 31 32 const url = `http://localhost:${port}`; 33 const client = h2.connect(url, common.mustCall(function() { 34 const headers = { 35 ':path': '/foobar', 36 ':method': 'GET', 37 ':scheme': 'http', 38 ':authority': `localhost:${port}`, 39 }; 40 const request = client.request(headers); 41 request.on('data', common.mustCall(function(chunk) { 42 // Cause an error on the server side 43 client.destroy(); 44 })); 45 request.end(); 46 })); 47 })); 48} 49 50{ 51 let expected = null; 52 53 const server = h2.createServer(); 54 55 process.on('uncaughtException', common.mustCall(function(err) { 56 assert.strictEqual(err.message, 'kaboom no handler'); 57 })); 58 59 server.on('stream', common.mustCall(function(stream) { 60 // There is no 'error' handler, and this will crash 61 stream.write('hello'); 62 stream.resume(); 63 64 expected = new Error('kaboom no handler'); 65 stream.destroy(expected); 66 server.close(); 67 })); 68 69 server.listen(0, common.mustCall(function() { 70 const port = server.address().port; 71 72 const url = `http://localhost:${port}`; 73 const client = h2.connect(url, common.mustCall(function() { 74 const headers = { 75 ':path': '/foobar', 76 ':method': 'GET', 77 ':scheme': 'http', 78 ':authority': `localhost:${port}`, 79 }; 80 const request = client.request(headers); 81 request.on('data', common.mustCall(function(chunk) { 82 // Cause an error on the server side 83 client.destroy(); 84 })); 85 request.end(); 86 })); 87 })); 88} 89