@@ -29,6 +29,7 @@ assert.deepStrictEqual(val, check);
29
29
[ 'maxHeaderListSize' , 2 ** 32 - 1 ] ,
30
30
[ 'maxHeaderSize' , 0 ] ,
31
31
[ 'maxHeaderSize' , 2 ** 32 - 1 ] ,
32
+ [ 'customSettings' , { '9999' : 301 } ] ,
32
33
] . forEach ( ( i ) => {
33
34
// Valid options should not throw.
34
35
http2 . getPackedSettings ( { [ i [ 0 ] ] : i [ 1 ] } ) ;
@@ -93,6 +94,7 @@ http2.getPackedSettings({ enablePush: false });
93
94
0x00 , 0x05 , 0x00 , 0x00 , 0x4e , 0x20 ,
94
95
0x00 , 0x06 , 0x00 , 0x00 , 0x00 , 0x64 ,
95
96
0x00 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 ,
97
+ 0x27 , 0x0F , 0x00 , 0x00 , 0x01 , 0x2d ,
96
98
] ) ;
97
99
98
100
const packed = http2 . getPackedSettings ( {
@@ -104,12 +106,90 @@ http2.getPackedSettings({ enablePush: false });
104
106
maxHeaderSize : 100 ,
105
107
enablePush : true ,
106
108
enableConnectProtocol : false ,
107
- foo : 'ignored'
109
+ foo : 'ignored' ,
110
+ customSettings : { '9999' : 301 }
108
111
} ) ;
109
- assert . strictEqual ( packed . length , 42 ) ;
112
+ assert . strictEqual ( packed . length , 48 ) ;
110
113
assert . deepStrictEqual ( packed , check ) ;
111
114
}
112
115
116
+ // Check if multiple custom settings can be set
117
+ {
118
+ const check = Buffer . from ( [
119
+ 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x64 ,
120
+ 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x01 ,
121
+ 0x00 , 0x03 , 0x00 , 0x00 , 0x00 , 0xc8 ,
122
+ 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x64 ,
123
+ 0x00 , 0x05 , 0x00 , 0x00 , 0x4e , 0x20 ,
124
+ 0x00 , 0x06 , 0x00 , 0x00 , 0x00 , 0x64 ,
125
+ 0x00 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 ,
126
+ 0x03 , 0xf3 , 0x00 , 0x00 , 0x07 , 0x9F ,
127
+ 0x0a , 0x2e , 0x00 , 0x00 , 0x00 , 0x58 ,
128
+ ] ) ;
129
+
130
+ const packed = http2 . getPackedSettings ( {
131
+ headerTableSize : 100 ,
132
+ initialWindowSize : 100 ,
133
+ maxFrameSize : 20000 ,
134
+ maxConcurrentStreams : 200 ,
135
+ maxHeaderListSize : 100 ,
136
+ maxHeaderSize : 100 ,
137
+ enablePush : true ,
138
+ enableConnectProtocol : false ,
139
+ customSettings : { '2606' : 88 , '1011' : 1951 }
140
+ } ) ;
141
+ assert . strictEqual ( packed . length , 54 ) ;
142
+ assert . deepStrictEqual ( packed , check ) ;
143
+ }
144
+
145
+ {
146
+ // Check if wrong custom settings cause an error
147
+
148
+ assert . throws ( ( ) => {
149
+ http2 . getPackedSettings ( {
150
+ customSettings : { '-1' : 659685 }
151
+ } ) ;
152
+ } , {
153
+ code : 'ERR_HTTP2_INVALID_SETTING_VALUE' ,
154
+ name : 'RangeError'
155
+ } ) ;
156
+
157
+ assert . throws ( ( ) => {
158
+ http2 . getPackedSettings ( {
159
+ customSettings : { '10' : 34577577777 }
160
+ } ) ;
161
+ } , {
162
+ code : 'ERR_HTTP2_INVALID_SETTING_VALUE' ,
163
+ name : 'RangeError'
164
+ } ) ;
165
+
166
+ assert . throws ( ( ) => {
167
+ http2 . getPackedSettings ( {
168
+ customSettings : { 'notvalid' : - 777 }
169
+ } ) ;
170
+ } , {
171
+ code : 'ERR_HTTP2_INVALID_SETTING_VALUE' ,
172
+ name : 'RangeError'
173
+ } ) ;
174
+
175
+ assert . throws ( ( ) => {
176
+ http2 . getPackedSettings ( {
177
+ customSettings : { '11' : 11 , '12' : 12 , '13' : 13 , '14' : 14 , '15' : 15 , '16' : 16 ,
178
+ '17' : 17 , '18' : 18 , '19' : 19 , '20' : 20 , '21' : 21 }
179
+ } ) ;
180
+ } , {
181
+ code : 'ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS'
182
+ } ) ;
183
+ assert . throws ( ( ) => {
184
+ http2 . getPackedSettings ( {
185
+ customSettings : { '11' : 11 , '12' : 12 , '13' : 13 , '14' : 14 , '15' : 15 , '16' : 16 ,
186
+ '17' : 17 , '18' : 18 , '19' : 19 , '20' : 20 , '21' : 21 , '22' : 22 }
187
+ } ) ;
188
+ } , {
189
+ code : 'ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS'
190
+ } ) ;
191
+ }
192
+
113
193
// Check for not passing settings.
114
194
{
115
195
const packed = http2 . getPackedSettings ( ) ;
@@ -124,7 +204,8 @@ http2.getPackedSettings({ enablePush: false });
124
204
0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x64 ,
125
205
0x00 , 0x06 , 0x00 , 0x00 , 0x00 , 0x64 ,
126
206
0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x01 ,
127
- 0x00 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ;
207
+ 0x00 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 ,
208
+ 0x27 , 0x0F , 0x00 , 0x00 , 0x01 , 0x2d ] ) ;
128
209
129
210
[ 1 , true , '' , [ ] , { } , NaN ] . forEach ( ( input ) => {
130
211
assert . throws ( ( ) => {
@@ -157,6 +238,7 @@ http2.getPackedSettings({ enablePush: false });
157
238
assert . strictEqual ( settings . maxHeaderSize , 100 ) ;
158
239
assert . strictEqual ( settings . enablePush , true ) ;
159
240
assert . strictEqual ( settings . enableConnectProtocol , false ) ;
241
+ assert . deepStrictEqual ( settings . customSettings , { '9999' : 301 } ) ;
160
242
}
161
243
162
244
{
0 commit comments