Skip to content

Commit ed259d2

Browse files
authored
Make http header list size configurable in HTTP client for HTTP2 (#12172)
Description This PR adds configurable maxHeaderListSize property to HTTP client configuration for HTTP2. Added maxHeaderListSize configuration property with getter/setter methods. Updated Http2FrameCodec instantiation to use the configurable header list size. Considerations Can be configured via micronaut.http.client.http2.max-header-list-size property.
1 parent f11ad23 commit ed259d2

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

http-client-core/src/main/java/io/micronaut/http/client/HttpClientConfiguration.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,12 +1274,20 @@ public static class Http2ClientConfiguration {
12741274
*/
12751275
public static final String PREFIX = "http2";
12761276

1277+
/**
1278+
* The default max header list size in bytes.
1279+
*/
1280+
@SuppressWarnings("WeakerAccess")
1281+
public static final int DEFAULT_MAX_HEADER_LIST_SIZE = 8192;
1282+
12771283
private Duration pingIntervalRead = null;
12781284

12791285
private Duration pingIntervalWrite = null;
12801286

12811287
private Duration pingIntervalIdle = null;
12821288

1289+
private int maxHeaderListSize = DEFAULT_MAX_HEADER_LIST_SIZE;
1290+
12831291
/**
12841292
* For HTTP/2 connections, the interval from the last inbound message to when an automated ping
12851293
* should be sent. This can be used to keep low-traffic connections alive.
@@ -1342,6 +1350,25 @@ public Duration getPingIntervalIdle() {
13421350
public void setPingIntervalIdle(@Nullable Duration pingIntervalIdle) {
13431351
this.pingIntervalIdle = pingIntervalIdle;
13441352
}
1353+
1354+
/**
1355+
* [available in the Netty HTTP client].
1356+
*
1357+
* @return The maximum allowed compressed header list size (in bytes) after decompression
1358+
* using HPACK (the HTTP/2 header compression algorithm).
1359+
*/
1360+
public int getMaxHeaderListSize() {
1361+
return maxHeaderListSize;
1362+
}
1363+
1364+
/**
1365+
* Sets the maximum header list size the client can handle. Default value ({@value io.micronaut.http.client.HttpClientConfiguration.Http2ClientConfiguration#DEFAULT_MAX_HEADER_LIST_SIZE}).
1366+
*
1367+
* @param maxHeaderListSize The maximum header list size the client can handle
1368+
*/
1369+
public void setMaxHeaderListSize(@ReadableBytes int maxHeaderListSize) {
1370+
this.maxHeaderListSize = maxHeaderListSize;
1371+
}
13451372
}
13461373

13471374
/**

http-client/src/main/java/io/micronaut/http/client/netty/ConnectionManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import io.netty.handler.codec.http2.Http2MultiplexActiveStreamsException;
8282
import io.netty.handler.codec.http2.Http2MultiplexHandler;
8383
import io.netty.handler.codec.http2.Http2PingFrame;
84+
import io.netty.handler.codec.http2.Http2Settings;
8485
import io.netty.handler.codec.http2.Http2SettingsAckFrame;
8586
import io.netty.handler.codec.http2.Http2SettingsFrame;
8687
import io.netty.handler.codec.http2.Http2StreamChannel;
@@ -654,7 +655,13 @@ final <V, C extends Future<V>> void withPropagation(Future<? extends V> channelF
654655
}
655656

656657
private Http2FrameCodec makeFrameCodec() {
657-
Http2FrameCodecBuilder builder = Http2FrameCodecBuilder.forClient();
658+
Http2Settings defaultSettings = Http2Settings.defaultSettings();
659+
660+
defaultSettings.maxHeaderListSize(configuration.getHttp2Configuration().getMaxHeaderListSize());
661+
662+
Http2FrameCodecBuilder builder = Http2FrameCodecBuilder.forClient()
663+
.initialSettings(defaultSettings);
664+
658665
configuration.getLogLevel().ifPresent(logLevel -> {
659666
try {
660667
final LogLevel nettyLevel =

0 commit comments

Comments
 (0)