1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const h2 = require('http2'); 8const Countdown = require('../common/countdown'); 9 10// Only allow one stream to be open at a time 11const server = h2.createServer({ settings: { maxConcurrentStreams: 1 } }); 12 13// The stream handler must be called only once 14server.on('stream', common.mustCall((stream) => { 15 stream.respond(); 16 stream.end('hello world'); 17})); 18 19server.listen(0, common.mustCall(() => { 20 const client = h2.connect(`http://localhost:${server.address().port}`); 21 22 const countdown = new Countdown(2, () => { 23 server.close(); 24 client.close(); 25 }); 26 27 client.on('remoteSettings', common.mustCall((settings) => { 28 assert.strictEqual(settings.maxConcurrentStreams, 1); 29 })); 30 31 // This one should go through with no problems 32 { 33 const req = client.request({ ':method': 'POST' }); 34 req.on('aborted', common.mustNotCall()); 35 req.on('response', common.mustCall()); 36 req.resume(); 37 req.on('end', common.mustCall()); 38 req.on('close', common.mustCall(() => countdown.dec())); 39 req.end(); 40 } 41 42 { 43 // This one should be aborted 44 const req = client.request({ ':method': 'POST' }); 45 req.on('aborted', common.mustCall()); 46 req.on('response', common.mustNotCall()); 47 req.resume(); 48 req.on('end', common.mustNotCall()); 49 req.on('close', common.mustCall(() => countdown.dec())); 50 req.on('error', common.expectsError({ 51 code: 'ERR_HTTP2_STREAM_ERROR', 52 name: 'Error', 53 message: 'Stream closed with error code NGHTTP2_REFUSED_STREAM' 54 })); 55 } 56})); 57