@@ -138,6 +138,9 @@ enum SettingsHandshake { READY, TRANSMITTED, ACKED }
138138 private int lowMark ;
139139
140140 private volatile H2Config remoteConfig ;
141+ private volatile long remoteHeaderTableSize ;
142+ private volatile long remoteMaxConcurrentStreams ;
143+ private volatile long remoteMaxHeaderListSize ;
141144
142145 private Continuation continuation ;
143146
@@ -205,6 +208,9 @@ enum SettingsHandshake { READY, TRANSMITTED, ACKED }
205208 this .hPackEncoder = new HPackEncoder (H2Config .INIT .getHeaderTableSize (), CharCodingSupport .createEncoder (charCodingConfig ));
206209 this .hPackDecoder = new HPackDecoder (H2Config .INIT .getHeaderTableSize (), CharCodingSupport .createDecoder (charCodingConfig ));
207210 this .remoteConfig = H2Config .INIT ;
211+ this .remoteHeaderTableSize = H2Config .INIT .getHeaderTableSize ();
212+ this .remoteMaxConcurrentStreams = H2Config .INIT .getMaxConcurrentStreams ();
213+ this .remoteMaxHeaderListSize = H2Config .INIT .getMaxHeaderListSize ();
208214 this .connInputWindow = new AtomicInteger (H2Config .INIT .getInitialWindowSize ());
209215 this .connOutputWindow = new AtomicInteger (H2Config .INIT .getInitialWindowSize ());
210216
@@ -576,7 +582,7 @@ public final void onOutput() throws HttpException, IOException {
576582 })));
577583 return ;
578584 }
579- while (streams .getLocalCount () < remoteConfig . getMaxConcurrentStreams () ) {
585+ while (streams .getLocalCount () < remoteMaxConcurrentStreams ) {
580586 final Command command = ioSession .poll ();
581587 if (command == null ) {
582588 break ;
@@ -1262,34 +1268,30 @@ private void consumeContinuationFrame(final RawFrame frame, final H2Stream strea
12621268
12631269 private void consumeSettingsFrame (final ByteBuffer payload ) throws IOException {
12641270 final H2Config .Builder configBuilder = H2Config .initial ();
1271+ long headerTableSize = remoteHeaderTableSize ;
1272+ long maxConcurrentStreams = remoteMaxConcurrentStreams ;
1273+ long maxHeaderListSize = remoteMaxHeaderListSize ;
12651274 while (payload .hasRemaining ()) {
12661275 final int code = payload .getShort ();
12671276 final int value = payload .getInt ();
12681277 final H2Param param = H2Param .valueOf (code );
12691278 if (param != null ) {
12701279 validateSetting (param , value );
1280+ final long unsignedValue = Integer .toUnsignedLong (value );
12711281 switch (param ) {
12721282 case HEADER_TABLE_SIZE :
1273- try {
1274- configBuilder .setHeaderTableSize (value );
1275- } catch (final IllegalArgumentException ex ) {
1276- throw new H2ConnectionException (H2Error .PROTOCOL_ERROR , ex .getMessage ());
1277- }
1283+ headerTableSize = unsignedValue ;
12781284 break ;
12791285 case MAX_CONCURRENT_STREAMS :
1280- try {
1281- configBuilder .setMaxConcurrentStreams (value );
1282- } catch (final IllegalArgumentException ex ) {
1283- throw new H2ConnectionException (H2Error .PROTOCOL_ERROR , ex .getMessage ());
1284- }
1286+ maxConcurrentStreams = unsignedValue ;
12851287 break ;
12861288 case ENABLE_PUSH :
12871289 configBuilder .setPushEnabled (value == 1 );
12881290 break ;
12891291 case INITIAL_WINDOW_SIZE :
12901292 if (value < 0 ) {
12911293 throw new H2ConnectionException (H2Error .FLOW_CONTROL_ERROR ,
1292- "Invalid initial window size: " + ( value & 0xffffffffL ) );
1294+ "Invalid initial window size: " + unsignedValue );
12931295 }
12941296 try {
12951297 configBuilder .setInitialWindowSize (value );
@@ -1305,19 +1307,19 @@ private void consumeSettingsFrame(final ByteBuffer payload) throws IOException {
13051307 }
13061308 break ;
13071309 case MAX_HEADER_LIST_SIZE :
1308- try {
1309- configBuilder .setMaxHeaderListSize (value );
1310- } catch (final IllegalArgumentException ex ) {
1311- throw new H2ConnectionException (H2Error .PROTOCOL_ERROR , ex .getMessage ());
1312- }
1310+ maxHeaderListSize = unsignedValue ;
13131311 break ;
13141312 case SETTINGS_NO_RFC7540_PRIORITIES :
13151313 peerNoRfc7540Priorities = value == 1 ;
13161314 break ;
13171315 }
13181316 }
13191317 }
1320- applyRemoteSettings (configBuilder .build ());
1318+ applyRemoteSettings (
1319+ configBuilder .build (),
1320+ headerTableSize ,
1321+ maxConcurrentStreams ,
1322+ maxHeaderListSize );
13211323 }
13221324
13231325 private void produceOutput () throws HttpException , IOException {
@@ -1339,12 +1341,19 @@ private void produceOutput() throws HttpException, IOException {
13391341 }
13401342 }
13411343
1342- private void applyRemoteSettings (final H2Config config ) throws H2ConnectionException {
1344+ private void applyRemoteSettings (
1345+ final H2Config config ,
1346+ final long headerTableSize ,
1347+ final long maxConcurrentStreams ,
1348+ final long maxHeaderListSize ) throws H2ConnectionException {
13431349 remoteConfig = config ;
1350+ remoteHeaderTableSize = headerTableSize ;
1351+ remoteMaxConcurrentStreams = maxConcurrentStreams ;
1352+ remoteMaxHeaderListSize = maxHeaderListSize ;
13441353
13451354 // The peer's HEADER_TABLE_SIZE is an upper bound for the encoder. Keep the local
13461355 // dynamic table bounded to limit memory usage and lookup cost per connection.
1347- hPackEncoder .setMaxTableSize (Math .min (remoteConfig . getHeaderTableSize () , H2Config .INIT .getHeaderTableSize ()));
1356+ hPackEncoder .setMaxTableSize (( int ) Math .min (remoteHeaderTableSize , H2Config .INIT .getHeaderTableSize ()));
13481357 final int delta = remoteConfig .getInitialWindowSize () - initOutputWinSize ;
13491358 initOutputWinSize = remoteConfig .getInitialWindowSize ();
13501359
0 commit comments