Skip to content

Commit 72251fc

Browse files
geoandvietj
authored andcommitted
Introduce an option for HTTP/2 upgrade max content length
Cherry-picked from 0c43faa
1 parent 920dfbf commit 72251fc

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

src/main/generated/io/vertx/core/http/HttpClientOptionsConverter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, HttpCli
8585
obj.setHttp2MultiplexingLimit(((Number)member.getValue()).intValue());
8686
}
8787
break;
88+
case "http2UpgradeMaxContentLength":
89+
if (member.getValue() instanceof Number) {
90+
obj.setHttp2UpgradeMaxContentLength(((Number)member.getValue()).intValue());
91+
}
92+
break;
8893
case "initialSettings":
8994
if (member.getValue() instanceof JsonObject) {
9095
obj.setInitialSettings(new io.vertx.core.http.Http2Settings((io.vertx.core.json.JsonObject)member.getValue()));
@@ -254,6 +259,7 @@ static void toJson(HttpClientOptions obj, java.util.Map<String, Object> json) {
254259
json.put("http2KeepAliveTimeout", obj.getHttp2KeepAliveTimeout());
255260
json.put("http2MaxPoolSize", obj.getHttp2MaxPoolSize());
256261
json.put("http2MultiplexingLimit", obj.getHttp2MultiplexingLimit());
262+
json.put("http2UpgradeMaxContentLength", obj.getHttp2UpgradeMaxContentLength());
257263
if (obj.getInitialSettings() != null) {
258264
json.put("initialSettings", obj.getInitialSettings().toJson());
259265
}

src/main/java/io/vertx/core/http/HttpClientOptions.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ public class HttpClientOptions extends ClientOptionsBase {
162162
*/
163163
public static final boolean DEFAULT_HTTP2_CLEAR_TEXT_UPGRADE_WITH_PREFLIGHT_REQUEST = false;
164164

165+
/**
166+
* Default maximum length of the aggregated content in bytes
167+
*/
168+
public static final int DEFAULT_HTTP2_UPGRADE_MAX_CONTENT_LENGTH = 65536;
169+
165170
/**
166171
* Default WebSocket masked bit is true as depicted by RFC = {@code false}
167172
*/
@@ -245,6 +250,7 @@ public class HttpClientOptions extends ClientOptionsBase {
245250
private int http2MultiplexingLimit;
246251
private int http2ConnectionWindowSize;
247252
private int http2KeepAliveTimeout;
253+
private int http2UpgradeMaxContentLength;
248254

249255
private boolean decompressionSupported;
250256
private int maxWebSocketFrameSize;
@@ -312,6 +318,7 @@ public HttpClientOptions(HttpClientOptions other) {
312318
this.http2MultiplexingLimit = other.http2MultiplexingLimit;
313319
this.http2ConnectionWindowSize = other.http2ConnectionWindowSize;
314320
this.http2KeepAliveTimeout = other.getHttp2KeepAliveTimeout();
321+
this.http2UpgradeMaxContentLength = other.getHttp2UpgradeMaxContentLength();
315322
this.decompressionSupported = other.decompressionSupported;
316323
this.maxWebSocketFrameSize = other.maxWebSocketFrameSize;
317324
this.maxWebSocketMessageSize = other.maxWebSocketMessageSize;
@@ -376,6 +383,7 @@ private void init() {
376383
http2MultiplexingLimit = DEFAULT_HTTP2_MULTIPLEXING_LIMIT;
377384
http2ConnectionWindowSize = DEFAULT_HTTP2_CONNECTION_WINDOW_SIZE;
378385
http2KeepAliveTimeout = DEFAULT_HTTP2_KEEP_ALIVE_TIMEOUT;
386+
http2UpgradeMaxContentLength = DEFAULT_HTTP2_UPGRADE_MAX_CONTENT_LENGTH;
379387
decompressionSupported = DEFAULT_DECOMPRESSION_SUPPORTED;
380388
maxWebSocketFrameSize = DEFAULT_MAX_WEBSOCKET_FRAME_SIZE;
381389
maxWebSocketMessageSize = DEFAULT_MAX_WEBSOCKET_MESSAGE_SIZE;
@@ -731,6 +739,28 @@ public HttpClientOptions setHttp2KeepAliveTimeout(int keepAliveTimeout) {
731739
return this;
732740
}
733741

742+
743+
/**
744+
* @return the HTTP/2 upgrade maximum length of the aggregated content in bytes
745+
*/
746+
public int getHttp2UpgradeMaxContentLength() {
747+
return http2UpgradeMaxContentLength;
748+
}
749+
750+
/**
751+
* Set the HTTP/2 upgrade maximum length of the aggregated content in bytes.
752+
* This is only taken into account when {@link HttpClientOptions#http2ClearTextUpgradeWithPreflightRequest} is set to {@code false} (which is the default).
753+
* When {@link HttpClientOptions#http2ClearTextUpgradeWithPreflightRequest} is {@code true}, then the client makes a preflight OPTIONS request
754+
* and the upgrade will not send a body, voiding the requirements.
755+
*
756+
* @param http2UpgradeMaxContentLength the length, in bytes
757+
* @return a reference to this, so the API can be used fluently
758+
*/
759+
public HttpClientOptions setHttp2UpgradeMaxContentLength(int http2UpgradeMaxContentLength) {
760+
this.http2UpgradeMaxContentLength = http2UpgradeMaxContentLength;
761+
return this;
762+
}
763+
734764
/**
735765
* Is keep alive enabled on the client?
736766
*

src/main/java/io/vertx/core/http/impl/Http2UpgradeClientConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public void upgradeTo(ChannelHandlerContext ctx, FullHttpResponse upgradeRespons
430430
handler.clientUpgrade(ctx);
431431
}
432432
};
433-
HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(httpCodec, upgradeCodec, 65536) {
433+
HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(httpCodec, upgradeCodec, upgradedConnection.client.options().getHttp2UpgradeMaxContentLength()) {
434434

435435
private long bufferedSize = 0;
436436
private Deque<Object> buffered = new ArrayDeque<>();

src/test/java/io/vertx/core/http/Http1xTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ public void testClientOptions() {
182182
assertEquals(options, options.setHttp2MultiplexingLimit(-1));
183183
assertEquals(-1, options.getHttp2MultiplexingLimit());
184184

185+
assertEquals(HttpClientOptions.DEFAULT_HTTP2_UPGRADE_MAX_CONTENT_LENGTH, options.getHttp2UpgradeMaxContentLength());
186+
rand = TestUtils.randomPositiveInt();
187+
assertEquals(options, options.setHttp2UpgradeMaxContentLength(rand));
188+
assertEquals(rand, options.getHttp2UpgradeMaxContentLength());
189+
assertEquals(options, options.setHttp2UpgradeMaxContentLength(-1));
190+
assertEquals(-1, options.getHttp2UpgradeMaxContentLength());
191+
185192
assertEquals(HttpClientOptions.DEFAULT_HTTP2_CONNECTION_WINDOW_SIZE, options.getHttp2ConnectionWindowSize());
186193
rand = TestUtils.randomPositiveInt();
187194
assertEquals(options, options.setHttp2ConnectionWindowSize(rand));
@@ -445,6 +452,7 @@ public void testCopyClientOptions() {
445452
int http2MaxPoolSize = TestUtils.randomPositiveInt();
446453
int http2MultiplexingLimit = TestUtils.randomPositiveInt();
447454
int http2ConnectionWindowSize = TestUtils.randomPositiveInt();
455+
int http2UpgradeMaxContentLength = TestUtils.randomPositiveInt();
448456
boolean decompressionSupported = rand.nextBoolean();
449457
HttpVersion protocolVersion = HttpVersion.HTTP_1_0;
450458
int maxChunkSize = TestUtils.randomPositiveInt();
@@ -501,6 +509,7 @@ public void testCopyClientOptions() {
501509
options.setDecoderInitialBufferSize(decoderInitialBufferSize);
502510
options.setKeepAliveTimeout(keepAliveTimeout);
503511
options.setHttp2KeepAliveTimeout(http2KeepAliveTimeout);
512+
options.setHttp2UpgradeMaxContentLength(http2UpgradeMaxContentLength);
504513
HttpClientOptions copy = new HttpClientOptions(options);
505514
checkCopyHttpClientOptions(options, copy);
506515
HttpClientOptions copy2 = new HttpClientOptions(options.toJson());
@@ -563,6 +572,7 @@ public void testDefaultClientOptionsJson() {
563572
assertEquals(def.getDecoderInitialBufferSize(), json.getDecoderInitialBufferSize());
564573
assertEquals(def.getKeepAliveTimeout(), json.getKeepAliveTimeout());
565574
assertEquals(def.getHttp2KeepAliveTimeout(), json.getHttp2KeepAliveTimeout());
575+
assertEquals(def.getHttp2UpgradeMaxContentLength(), json.getHttp2UpgradeMaxContentLength());
566576
}
567577

568578
@Test
@@ -615,6 +625,7 @@ public void testClientOptionsJson() {
615625
int decoderInitialBufferSize = TestUtils.randomPositiveInt();
616626
int keepAliveTimeout = TestUtils.randomPositiveInt();
617627
int http2KeepAliveTimeout = TestUtils.randomPositiveInt();
628+
int http2UpgradeMaxContentLength = TestUtils.randomPositiveInt();
618629

619630
JsonObject json = new JsonObject();
620631
json.put("sendBufferSize", sendBufferSize)
@@ -661,7 +672,8 @@ public void testClientOptionsJson() {
661672
.put("localAddress", localAddress)
662673
.put("decoderInitialBufferSize", decoderInitialBufferSize)
663674
.put("keepAliveTimeout", keepAliveTimeout)
664-
.put("http2KeepAliveTimeout", http2KeepAliveTimeout);
675+
.put("http2KeepAliveTimeout", http2KeepAliveTimeout)
676+
.put("http2UpgradeMaxContentLength", http2UpgradeMaxContentLength);
665677

666678
HttpClientOptions options = new HttpClientOptions(json);
667679
assertEquals(sendBufferSize, options.getSendBufferSize());

0 commit comments

Comments
 (0)