From 322d0954cab40aab579a518a2cb87549bc88ae11 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Tue, 8 Aug 2023 09:52:32 +0200 Subject: [PATCH] When the server upgrades an HTTP/1.1 connection to H2C, it forwards inbound HTTP messages to the H2 encoder and updates the frame controller with the received amount of bytes. Actually such messages are not taken in account by the H2 flow controller and therefore when the window size becomes zero, it will not process message anymore. This impacts HTTP/1.1 upgrades to H2C sending messages payload greater than the flow control window size. The VertxHttp2ConnectionHandler has been updated to not account for received HTTP/1.1 bytes. --- .../impl/VertxHttp2ConnectionHandler.java | 3 --- .../Http2WithUpgradeServerFileUploadTest.java | 24 +++++++++++++++++++ .../core/http/HttpServerFileUploadTest.java | 16 +++++-------- 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 src/test/java/io/vertx/core/http/Http2WithUpgradeServerFileUploadTest.java diff --git a/src/main/java/io/vertx/core/http/impl/VertxHttp2ConnectionHandler.java b/src/main/java/io/vertx/core/http/impl/VertxHttp2ConnectionHandler.java index 7588d1dfeb9..2d566444847 100644 --- a/src/main/java/io/vertx/core/http/impl/VertxHttp2ConnectionHandler.java +++ b/src/main/java/io/vertx/core/http/impl/VertxHttp2ConnectionHandler.java @@ -409,9 +409,6 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception connection.onHeadersRead(ctx, 1, frame.headers(), frame.padding(), frame.isEndStream()); } else if (msg instanceof Http2DataFrame) { Http2DataFrame frame = (Http2DataFrame) msg; - Http2LocalFlowController controller = decoder().flowController(); - Http2Stream stream = decoder().connection().stream(1); - controller.receiveFlowControlledFrame(stream, frame.content(), frame.padding(), frame.isEndStream()); connection.onDataRead(ctx, 1, frame.content(), frame.padding(), frame.isEndStream()); } } else { diff --git a/src/test/java/io/vertx/core/http/Http2WithUpgradeServerFileUploadTest.java b/src/test/java/io/vertx/core/http/Http2WithUpgradeServerFileUploadTest.java new file mode 100644 index 00000000000..17660b98831 --- /dev/null +++ b/src/test/java/io/vertx/core/http/Http2WithUpgradeServerFileUploadTest.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011-2019 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + */ +package io.vertx.core.http; + +/** + */ +public class Http2WithUpgradeServerFileUploadTest extends HttpServerFileUploadTest { + + @Override + protected HttpClientOptions createBaseClientOptions() { + return new HttpClientOptions() + .setProtocolVersion(HttpVersion.HTTP_2) + .setHttp2ClearTextUpgrade(true); + } + +} diff --git a/src/test/java/io/vertx/core/http/HttpServerFileUploadTest.java b/src/test/java/io/vertx/core/http/HttpServerFileUploadTest.java index e3caa77ee83..4552ee72a73 100644 --- a/src/test/java/io/vertx/core/http/HttpServerFileUploadTest.java +++ b/src/test/java/io/vertx/core/http/HttpServerFileUploadTest.java @@ -331,16 +331,12 @@ private void testFormUploadFile(String filename, "\r\n"; req.headers().set("content-length", "" + (pro + contentStr + epi).length()); req.headers().set("content-type", "multipart/form-data; boundary=" + boundary); - if (abortClient || cancelStream) { - Future fut = req.write(pro + contentStr.substring(0, contentStr.length() / 2)); - if (abortClient) { - fut.onComplete(onSuccess(v -> { - clientConn.set(req.connection()); - checkClose.run(); - })); - } - } else { - req.end(pro + contentStr + epi); + Future fut = req.end(pro + contentStr + epi); + if (abortClient) { + fut.onComplete(onSuccess(v -> { + clientConn.set(req.connection()); + checkClose.run(); + })); } if (abortClient) { req.response(onFailure(err -> complete()));