2017-07-17 10:29:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2017-08-07 07:54:44 +02:00
|
|
|
if (!common.hasCrypto)
|
|
|
|
common.skip('missing crypto');
|
2017-07-17 10:29:42 -07:00
|
|
|
const assert = require('assert');
|
|
|
|
const h2 = require('http2');
|
2017-12-12 11:34:17 -08:00
|
|
|
const Countdown = require('../common/countdown');
|
2017-07-17 10:29:42 -07:00
|
|
|
|
|
|
|
// Only allow one stream to be open at a time
|
2017-07-22 09:20:53 -07:00
|
|
|
const server = h2.createServer({ settings: { maxConcurrentStreams: 1 } });
|
2017-07-17 10:29:42 -07:00
|
|
|
|
|
|
|
// The stream handler must be called only once
|
|
|
|
server.on('stream', common.mustCall((stream) => {
|
2017-12-12 11:34:17 -08:00
|
|
|
stream.respond();
|
2017-07-17 10:29:42 -07:00
|
|
|
stream.end('hello world');
|
|
|
|
}));
|
|
|
|
|
2017-12-12 11:34:17 -08:00
|
|
|
server.listen(0, common.mustCall(() => {
|
2017-07-17 10:29:42 -07:00
|
|
|
const client = h2.connect(`http://localhost:${server.address().port}`);
|
|
|
|
|
2017-12-12 11:34:17 -08:00
|
|
|
const countdown = new Countdown(2, () => {
|
|
|
|
server.close();
|
|
|
|
client.close();
|
|
|
|
});
|
2017-07-17 10:29:42 -07:00
|
|
|
|
|
|
|
client.on('remoteSettings', common.mustCall((settings) => {
|
|
|
|
assert.strictEqual(settings.maxConcurrentStreams, 1);
|
|
|
|
}));
|
|
|
|
|
|
|
|
// This one should go through with no problems
|
2017-12-12 11:34:17 -08:00
|
|
|
{
|
|
|
|
const req = client.request({ ':method': 'POST' });
|
|
|
|
req.on('aborted', common.mustNotCall());
|
|
|
|
req.on('response', common.mustCall());
|
|
|
|
req.resume();
|
|
|
|
req.on('end', common.mustCall());
|
|
|
|
req.on('close', common.mustCall(() => countdown.dec()));
|
|
|
|
req.end();
|
|
|
|
}
|
2017-07-17 10:29:42 -07:00
|
|
|
|
2017-12-12 11:34:17 -08:00
|
|
|
{
|
|
|
|
// This one should be aborted
|
|
|
|
const req = client.request({ ':method': 'POST' });
|
|
|
|
req.on('aborted', common.mustCall());
|
|
|
|
req.on('response', common.mustNotCall());
|
|
|
|
req.resume();
|
2018-05-01 00:29:16 -04:00
|
|
|
req.on('end', common.mustCall());
|
2017-12-12 11:34:17 -08:00
|
|
|
req.on('close', common.mustCall(() => countdown.dec()));
|
|
|
|
req.on('error', common.expectsError({
|
|
|
|
code: 'ERR_HTTP2_STREAM_ERROR',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'Error',
|
2018-02-23 22:28:29 +01:00
|
|
|
message: 'Stream closed with error code NGHTTP2_REFUSED_STREAM'
|
2017-12-12 11:34:17 -08:00
|
|
|
}));
|
|
|
|
}
|
2017-07-17 10:29:42 -07:00
|
|
|
}));
|