11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst http2 = require('http2'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst server = http2.createServer(); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciserver.on('session', common.mustCall((session) => { 121cb0ef41Sopenharmony_ci // Verify that the settings disabling push is received 131cb0ef41Sopenharmony_ci session.on('remoteSettings', common.mustCall((settings) => { 141cb0ef41Sopenharmony_ci assert.strictEqual(settings.enablePush, false); 151cb0ef41Sopenharmony_ci })); 161cb0ef41Sopenharmony_ci})); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciserver.on('stream', common.mustCall((stream) => { 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci // The client has disabled push streams, so pushAllowed must be false, 211cb0ef41Sopenharmony_ci // and pushStream() must throw. 221cb0ef41Sopenharmony_ci assert.strictEqual(stream.pushAllowed, false); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci assert.throws(() => { 251cb0ef41Sopenharmony_ci stream.pushStream({ 261cb0ef41Sopenharmony_ci ':scheme': 'http', 271cb0ef41Sopenharmony_ci ':path': '/foobar', 281cb0ef41Sopenharmony_ci ':authority': `localhost:${server.address().port}`, 291cb0ef41Sopenharmony_ci }, common.mustNotCall()); 301cb0ef41Sopenharmony_ci }, { 311cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_PUSH_DISABLED', 321cb0ef41Sopenharmony_ci name: 'Error' 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci stream.respond({ ':status': 200 }); 361cb0ef41Sopenharmony_ci stream.end('test'); 371cb0ef41Sopenharmony_ci})); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 401cb0ef41Sopenharmony_ci const options = { settings: { enablePush: false } }; 411cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`, 421cb0ef41Sopenharmony_ci options); 431cb0ef41Sopenharmony_ci const req = client.request({ ':path': '/' }); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci // Because push streams are disabled, this must not be called. 461cb0ef41Sopenharmony_ci client.on('stream', common.mustNotCall()); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci req.resume(); 491cb0ef41Sopenharmony_ci req.on('end', common.mustCall(() => { 501cb0ef41Sopenharmony_ci server.close(); 511cb0ef41Sopenharmony_ci client.close(); 521cb0ef41Sopenharmony_ci })); 531cb0ef41Sopenharmony_ci req.end(); 541cb0ef41Sopenharmony_ci})); 55