1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const h2 = require('http2'); 8 9// Check that pause & resume work as expected with Http2ServerRequest 10 11const testStr = 'Request Body from Client'; 12 13const server = h2.createServer(); 14 15server.on('request', common.mustCall((req, res) => { 16 let data = ''; 17 req.pause(); 18 req.setEncoding('utf8'); 19 req.on('data', common.mustCall((chunk) => (data += chunk))); 20 setTimeout(common.mustCall(() => { 21 assert.strictEqual(data, ''); 22 req.resume(); 23 }), common.platformTimeout(100)); 24 req.on('end', common.mustCall(() => { 25 assert.strictEqual(data, testStr); 26 res.end(); 27 })); 28 29 // Shouldn't throw if underlying Http2Stream no longer exists 30 res.on('finish', common.mustCall(() => process.nextTick(() => { 31 req.pause(); 32 req.resume(); 33 }))); 34})); 35 36server.listen(0, common.mustCall(() => { 37 const port = server.address().port; 38 39 const client = h2.connect(`http://localhost:${port}`); 40 const request = client.request({ 41 ':path': '/foobar', 42 ':method': 'POST', 43 ':scheme': 'http', 44 ':authority': `localhost:${port}` 45 }); 46 request.resume(); 47 request.end(testStr); 48 request.on('end', common.mustCall(function() { 49 client.close(); 50 server.close(); 51 })); 52})); 53