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 11server.on('stream', common.mustCall(onStream)); 12 13function onStream(stream, headers, flags) { 14 15 // Test Stream State. 16 { 17 const state = stream.state; 18 assert.strictEqual(typeof state, 'object'); 19 assert.strictEqual(typeof state.state, 'number'); 20 assert.strictEqual(typeof state.weight, 'number'); 21 assert.strictEqual(typeof state.sumDependencyWeight, 'number'); 22 assert.strictEqual(typeof state.localClose, 'number'); 23 assert.strictEqual(typeof state.remoteClose, 'number'); 24 assert.strictEqual(typeof state.localWindowSize, 'number'); 25 } 26 27 // Test Session State. 28 { 29 const state = stream.session.state; 30 assert.strictEqual(typeof state, 'object'); 31 assert.strictEqual(typeof state.effectiveLocalWindowSize, 'number'); 32 assert.strictEqual(typeof state.effectiveRecvDataLength, 'number'); 33 assert.strictEqual(typeof state.nextStreamID, 'number'); 34 assert.strictEqual(typeof state.localWindowSize, 'number'); 35 assert.strictEqual(typeof state.lastProcStreamID, 'number'); 36 assert.strictEqual(typeof state.remoteWindowSize, 'number'); 37 assert.strictEqual(typeof state.outboundQueueSize, 'number'); 38 assert.strictEqual(typeof state.deflateDynamicTableSize, 'number'); 39 assert.strictEqual(typeof state.inflateDynamicTableSize, 'number'); 40 } 41 42 stream.respond({ 43 'content-type': 'text/html', 44 ':status': 200 45 }); 46 stream.end('hello world'); 47} 48 49server.listen(0); 50 51server.on('listening', common.mustCall(() => { 52 53 const client = h2.connect(`http://localhost:${server.address().port}`); 54 55 const headers = { ':path': '/' }; 56 57 const req = client.request(headers); 58 59 // State will only be valid after connect event is emitted 60 req.on('ready', common.mustCall(() => { 61 62 // Test Stream State. 63 { 64 const state = req.state; 65 assert.strictEqual(typeof state, 'object'); 66 assert.strictEqual(typeof state.state, 'number'); 67 assert.strictEqual(typeof state.weight, 'number'); 68 assert.strictEqual(typeof state.sumDependencyWeight, 'number'); 69 assert.strictEqual(typeof state.localClose, 'number'); 70 assert.strictEqual(typeof state.remoteClose, 'number'); 71 assert.strictEqual(typeof state.localWindowSize, 'number'); 72 } 73 74 // Test Session State 75 { 76 const state = req.session.state; 77 assert.strictEqual(typeof state, 'object'); 78 assert.strictEqual(typeof state.effectiveLocalWindowSize, 'number'); 79 assert.strictEqual(typeof state.effectiveRecvDataLength, 'number'); 80 assert.strictEqual(typeof state.nextStreamID, 'number'); 81 assert.strictEqual(typeof state.localWindowSize, 'number'); 82 assert.strictEqual(typeof state.lastProcStreamID, 'number'); 83 assert.strictEqual(typeof state.remoteWindowSize, 'number'); 84 assert.strictEqual(typeof state.outboundQueueSize, 'number'); 85 assert.strictEqual(typeof state.deflateDynamicTableSize, 'number'); 86 assert.strictEqual(typeof state.inflateDynamicTableSize, 'number'); 87 } 88 })); 89 90 req.on('response', common.mustCall()); 91 req.resume(); 92 req.on('end', common.mustCall(() => { 93 server.close(); 94 client.close(); 95 })); 96 req.end(); 97 98})); 99