1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const http2 = require('http2'); 8 9// Test that maxSessionMemory Caps work 10 11const largeBuffer = Buffer.alloc(2e6); 12 13const server = http2.createServer({ maxSessionMemory: 1 }); 14 15server.on('stream', common.mustCall((stream) => { 16 stream.on('error', (err) => { 17 if (err.code !== 'ECONNRESET') 18 throw err; 19 }); 20 stream.respond(); 21 stream.end(largeBuffer); 22})); 23 24server.listen(0, common.mustCall(() => { 25 const client = http2.connect(`http://localhost:${server.address().port}`); 26 27 { 28 const req = client.request(); 29 30 req.on('response', () => { 31 // This one should be rejected because the server is over budget 32 // on the current memory allocation 33 const req = client.request(); 34 req.on('error', common.expectsError({ 35 code: 'ERR_HTTP2_STREAM_ERROR', 36 name: 'Error', 37 message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM' 38 })); 39 req.on('close', common.mustCall(() => { 40 server.close(); 41 client.destroy(); 42 })); 43 }); 44 45 req.resume(); 46 req.on('close', common.mustCall()); 47 } 48})); 49