|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +if (!common.hasCrypto) |
| 5 | + common.skip('missing crypto'); |
| 6 | + |
| 7 | +const assert = require('assert'); |
| 8 | +const http2 = require('http2'); |
| 9 | + |
| 10 | +{ |
| 11 | + const server = http2.createServer(); |
| 12 | + server.on('stream', common.mustNotCall((stream) => { |
| 13 | + stream.respond(); |
| 14 | + stream.end('ok'); |
| 15 | + })); |
| 16 | + |
| 17 | + const types = { |
| 18 | + boolean: true, |
| 19 | + function: () => {}, |
| 20 | + number: 1, |
| 21 | + object: {}, |
| 22 | + array: [], |
| 23 | + null: null, |
| 24 | + }; |
| 25 | + |
| 26 | + server.listen(0, common.mustCall(() => { |
| 27 | + const client = http2.connect(`http://localhost:${server.address().port}`); |
| 28 | + |
| 29 | + client.on('connect', common.mustCall(() => { |
| 30 | + const outOfRangeNum = 2 ** 32; |
| 31 | + assert.throws( |
| 32 | + () => client.setLocalWindowSize(outOfRangeNum), |
| 33 | + { |
| 34 | + name: 'RangeError', |
| 35 | + code: 'ERR_OUT_OF_RANGE', |
| 36 | + message: 'The value of "windowSize" is out of range.' + |
| 37 | + ' It must be >= 0 && <= 2147483647. Received ' + outOfRangeNum |
| 38 | + } |
| 39 | + ); |
| 40 | + |
| 41 | + // Throw if something other than number is passed to setLocalWindowSize |
| 42 | + Object.entries(types).forEach(([type, value]) => { |
| 43 | + if (type === 'number') { |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + assert.throws( |
| 48 | + () => client.setLocalWindowSize(value), |
| 49 | + { |
| 50 | + name: 'TypeError', |
| 51 | + code: 'ERR_INVALID_ARG_TYPE', |
| 52 | + message: 'The "windowSize" argument must be of type number.' + |
| 53 | + common.invalidArgTypeHelper(value) |
| 54 | + } |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + server.close(); |
| 59 | + client.close(); |
| 60 | + })); |
| 61 | + })); |
| 62 | +} |
| 63 | + |
| 64 | +{ |
| 65 | + const server = http2.createServer(); |
| 66 | + server.on('stream', common.mustNotCall((stream) => { |
| 67 | + stream.respond(); |
| 68 | + stream.end('ok'); |
| 69 | + })); |
| 70 | + |
| 71 | + server.listen(0, common.mustCall(() => { |
| 72 | + const client = http2.connect(`http://localhost:${server.address().port}`); |
| 73 | + |
| 74 | + client.on('connect', common.mustCall(() => { |
| 75 | + const windowSize = 2 ** 20; |
| 76 | + const defaultSetting = http2.getDefaultSettings(); |
| 77 | + client.setLocalWindowSize(windowSize); |
| 78 | + |
| 79 | + assert.strictEqual(client.state.effectiveLocalWindowSize, windowSize); |
| 80 | + assert.strictEqual(client.state.localWindowSize, windowSize); |
| 81 | + assert.strictEqual( |
| 82 | + client.state.remoteWindowSize, |
| 83 | + defaultSetting.initialWindowSize |
| 84 | + ); |
| 85 | + |
| 86 | + server.close(); |
| 87 | + client.close(); |
| 88 | + })); |
| 89 | + })); |
| 90 | +} |
| 91 | + |
| 92 | +{ |
| 93 | + const server = http2.createServer(); |
| 94 | + server.on('stream', common.mustNotCall((stream) => { |
| 95 | + stream.respond(); |
| 96 | + stream.end('ok'); |
| 97 | + })); |
| 98 | + |
| 99 | + server.listen(0, common.mustCall(() => { |
| 100 | + const client = http2.connect(`http://localhost:${server.address().port}`); |
| 101 | + |
| 102 | + client.on('connect', common.mustCall(() => { |
| 103 | + const windowSize = 20; |
| 104 | + const defaultSetting = http2.getDefaultSettings(); |
| 105 | + client.setLocalWindowSize(windowSize); |
| 106 | + |
| 107 | + assert.strictEqual(client.state.effectiveLocalWindowSize, windowSize); |
| 108 | + assert.strictEqual( |
| 109 | + client.state.localWindowSize, |
| 110 | + defaultSetting.initialWindowSize |
| 111 | + ); |
| 112 | + assert.strictEqual( |
| 113 | + client.state.remoteWindowSize, |
| 114 | + defaultSetting.initialWindowSize |
| 115 | + ); |
| 116 | + |
| 117 | + server.close(); |
| 118 | + client.close(); |
| 119 | + })); |
| 120 | + })); |
| 121 | +} |
0 commit comments