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 9const server = h2.createServer(); 10 11// We use the lower-level API here 12server.on('stream', common.mustCall(onStream)); 13 14function onPriority(stream, parent, weight, exclusive) { 15 assert.strictEqual(stream, 1); 16 assert.strictEqual(parent, 0); 17 assert.strictEqual(weight, 1); 18 assert.strictEqual(exclusive, false); 19} 20 21function onStream(stream, headers, flags) { 22 stream.priority({ 23 parent: 0, 24 weight: 1, 25 exclusive: false 26 }); 27 stream.respond({ 28 'content-type': 'text/html', 29 ':status': 200 30 }); 31 stream.end('hello world'); 32} 33 34server.listen(0); 35 36server.on('priority', common.mustCall(onPriority)); 37 38server.on('listening', common.mustCall(() => { 39 40 const client = h2.connect(`http://localhost:${server.address().port}`); 41 const req = client.request({ ':path': '/' }); 42 43 client.on('connect', () => { 44 req.priority({ 45 parent: 0, 46 weight: 1, 47 exclusive: false 48 }); 49 }); 50 51 req.on('priority', common.mustCall(onPriority)); 52 53 req.on('response', common.mustCall()); 54 req.resume(); 55 req.on('end', common.mustCall(() => { 56 server.close(); 57 client.close(); 58 })); 59 req.end(); 60 61})); 62