Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, HttpCli
obj.setHttp2MultiplexingLimit(((Number)member.getValue()).intValue());
}
break;
case "http2UpgradeMaxContentLength":
if (member.getValue() instanceof Number) {
obj.setHttp2UpgradeMaxContentLength(((Number)member.getValue()).intValue());
}
break;
case "initialSettings":
if (member.getValue() instanceof JsonObject) {
obj.setInitialSettings(new io.vertx.core.http.Http2Settings((io.vertx.core.json.JsonObject)member.getValue()));
Expand Down Expand Up @@ -254,6 +259,7 @@ static void toJson(HttpClientOptions obj, java.util.Map<String, Object> json) {
json.put("http2KeepAliveTimeout", obj.getHttp2KeepAliveTimeout());
json.put("http2MaxPoolSize", obj.getHttp2MaxPoolSize());
json.put("http2MultiplexingLimit", obj.getHttp2MultiplexingLimit());
json.put("http2UpgradeMaxContentLength", obj.getHttp2UpgradeMaxContentLength());
if (obj.getInitialSettings() != null) {
json.put("initialSettings", obj.getInitialSettings().toJson());
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/io/vertx/core/http/HttpClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public class HttpClientOptions extends ClientOptionsBase {
*/
public static final boolean DEFAULT_HTTP2_CLEAR_TEXT_UPGRADE_WITH_PREFLIGHT_REQUEST = false;

/**
* Default maximum length of the aggregated content in bytes
*/
public static final int DEFAULT_HTTP2_UPGRADE_MAX_CONTENT_LENGTH = 65536;

/**
* Default WebSocket masked bit is true as depicted by RFC = {@code false}
*/
Expand Down Expand Up @@ -245,6 +250,7 @@ public class HttpClientOptions extends ClientOptionsBase {
private int http2MultiplexingLimit;
private int http2ConnectionWindowSize;
private int http2KeepAliveTimeout;
private int http2UpgradeMaxContentLength;

private boolean decompressionSupported;
private int maxWebSocketFrameSize;
Expand Down Expand Up @@ -312,6 +318,7 @@ public HttpClientOptions(HttpClientOptions other) {
this.http2MultiplexingLimit = other.http2MultiplexingLimit;
this.http2ConnectionWindowSize = other.http2ConnectionWindowSize;
this.http2KeepAliveTimeout = other.getHttp2KeepAliveTimeout();
this.http2UpgradeMaxContentLength = other.getHttp2UpgradeMaxContentLength();
this.decompressionSupported = other.decompressionSupported;
this.maxWebSocketFrameSize = other.maxWebSocketFrameSize;
this.maxWebSocketMessageSize = other.maxWebSocketMessageSize;
Expand Down Expand Up @@ -376,6 +383,7 @@ private void init() {
http2MultiplexingLimit = DEFAULT_HTTP2_MULTIPLEXING_LIMIT;
http2ConnectionWindowSize = DEFAULT_HTTP2_CONNECTION_WINDOW_SIZE;
http2KeepAliveTimeout = DEFAULT_HTTP2_KEEP_ALIVE_TIMEOUT;
http2UpgradeMaxContentLength = DEFAULT_HTTP2_UPGRADE_MAX_CONTENT_LENGTH;
decompressionSupported = DEFAULT_DECOMPRESSION_SUPPORTED;
maxWebSocketFrameSize = DEFAULT_MAX_WEBSOCKET_FRAME_SIZE;
maxWebSocketMessageSize = DEFAULT_MAX_WEBSOCKET_MESSAGE_SIZE;
Expand Down Expand Up @@ -731,6 +739,28 @@ public HttpClientOptions setHttp2KeepAliveTimeout(int keepAliveTimeout) {
return this;
}


/**
* @return the HTTP/2 upgrade maximum length of the aggregated content in bytes
*/
public int getHttp2UpgradeMaxContentLength() {
return http2UpgradeMaxContentLength;
}

/**
* Set the HTTP/2 upgrade maximum length of the aggregated content in bytes.
* This is only taken into account when {@link HttpClientOptions#http2ClearTextUpgradeWithPreflightRequest} is set to {@code false} (which is the default).
* When {@link HttpClientOptions#http2ClearTextUpgradeWithPreflightRequest} is {@code true}, then the client makes a preflight OPTIONS request
* and the upgrade will not send a body, voiding the requirements.
*
* @param http2UpgradeMaxContentLength the length, in bytes
* @return a reference to this, so the API can be used fluently
*/
public HttpClientOptions setHttp2UpgradeMaxContentLength(int http2UpgradeMaxContentLength) {
this.http2UpgradeMaxContentLength = http2UpgradeMaxContentLength;
return this;
}

/**
* Is keep alive enabled on the client?
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void upgradeTo(ChannelHandlerContext ctx, FullHttpResponse upgradeRespons
handler.clientUpgrade(ctx);
}
};
HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(httpCodec, upgradeCodec, 65536) {
HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(httpCodec, upgradeCodec, upgradedConnection.client.options().getHttp2UpgradeMaxContentLength()) {

private long bufferedSize = 0;
private Deque<Object> buffered = new ArrayDeque<>();
Expand Down
14 changes: 13 additions & 1 deletion src/test/java/io/vertx/core/http/Http1xTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ public void testClientOptions() {
assertEquals(options, options.setHttp2MultiplexingLimit(-1));
assertEquals(-1, options.getHttp2MultiplexingLimit());

assertEquals(HttpClientOptions.DEFAULT_HTTP2_UPGRADE_MAX_CONTENT_LENGTH, options.getHttp2UpgradeMaxContentLength());
rand = TestUtils.randomPositiveInt();
assertEquals(options, options.setHttp2UpgradeMaxContentLength(rand));
assertEquals(rand, options.getHttp2UpgradeMaxContentLength());
assertEquals(options, options.setHttp2UpgradeMaxContentLength(-1));
assertEquals(-1, options.getHttp2UpgradeMaxContentLength());

assertEquals(HttpClientOptions.DEFAULT_HTTP2_CONNECTION_WINDOW_SIZE, options.getHttp2ConnectionWindowSize());
rand = TestUtils.randomPositiveInt();
assertEquals(options, options.setHttp2ConnectionWindowSize(rand));
Expand Down Expand Up @@ -445,6 +452,7 @@ public void testCopyClientOptions() {
int http2MaxPoolSize = TestUtils.randomPositiveInt();
int http2MultiplexingLimit = TestUtils.randomPositiveInt();
int http2ConnectionWindowSize = TestUtils.randomPositiveInt();
int http2UpgradeMaxContentLength = TestUtils.randomPositiveInt();
boolean decompressionSupported = rand.nextBoolean();
HttpVersion protocolVersion = HttpVersion.HTTP_1_0;
int maxChunkSize = TestUtils.randomPositiveInt();
Expand Down Expand Up @@ -501,6 +509,7 @@ public void testCopyClientOptions() {
options.setDecoderInitialBufferSize(decoderInitialBufferSize);
options.setKeepAliveTimeout(keepAliveTimeout);
options.setHttp2KeepAliveTimeout(http2KeepAliveTimeout);
options.setHttp2UpgradeMaxContentLength(http2UpgradeMaxContentLength);
HttpClientOptions copy = new HttpClientOptions(options);
checkCopyHttpClientOptions(options, copy);
HttpClientOptions copy2 = new HttpClientOptions(options.toJson());
Expand Down Expand Up @@ -563,6 +572,7 @@ public void testDefaultClientOptionsJson() {
assertEquals(def.getDecoderInitialBufferSize(), json.getDecoderInitialBufferSize());
assertEquals(def.getKeepAliveTimeout(), json.getKeepAliveTimeout());
assertEquals(def.getHttp2KeepAliveTimeout(), json.getHttp2KeepAliveTimeout());
assertEquals(def.getHttp2UpgradeMaxContentLength(), json.getHttp2UpgradeMaxContentLength());
}

@Test
Expand Down Expand Up @@ -615,6 +625,7 @@ public void testClientOptionsJson() {
int decoderInitialBufferSize = TestUtils.randomPositiveInt();
int keepAliveTimeout = TestUtils.randomPositiveInt();
int http2KeepAliveTimeout = TestUtils.randomPositiveInt();
int http2UpgradeMaxContentLength = TestUtils.randomPositiveInt();

JsonObject json = new JsonObject();
json.put("sendBufferSize", sendBufferSize)
Expand Down Expand Up @@ -661,7 +672,8 @@ public void testClientOptionsJson() {
.put("localAddress", localAddress)
.put("decoderInitialBufferSize", decoderInitialBufferSize)
.put("keepAliveTimeout", keepAliveTimeout)
.put("http2KeepAliveTimeout", http2KeepAliveTimeout);
.put("http2KeepAliveTimeout", http2KeepAliveTimeout)
.put("http2UpgradeMaxContentLength", http2UpgradeMaxContentLength);

HttpClientOptions options = new HttpClientOptions(json);
assertEquals(sendBufferSize, options.getSendBufferSize());
Expand Down
Loading