From adbe97600cc6215f15ce2fac629c89f93618ca8f Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Mon, 25 Mar 2024 17:38:11 +0100 Subject: [PATCH] Fix a regression in HttpServerRequest#isExpectMultipart due to the cleanup of the form. --- .../java/io/vertx/core/http/impl/Http1xServerRequest.java | 8 ++++---- .../java/io/vertx/core/http/impl/Http2ServerRequest.java | 4 +++- .../java/io/vertx/core/http/HttpServerFileUploadTest.java | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/vertx/core/http/impl/Http1xServerRequest.java b/src/main/java/io/vertx/core/http/impl/Http1xServerRequest.java index fca64f5e9e1..8afedf08d4d 100644 --- a/src/main/java/io/vertx/core/http/impl/Http1xServerRequest.java +++ b/src/main/java/io/vertx/core/http/impl/Http1xServerRequest.java @@ -93,6 +93,7 @@ public class Http1xServerRequest extends HttpServerRequestInternal implements io private HttpEventHandler eventHandler; private Handler uploadHandler; private MultiMap attributes; + private boolean expectMultipart; private HttpPostRequestDecoder decoder; private boolean ended; private long bytesRead; @@ -473,6 +474,7 @@ private void webSocket(PromiseInternal promise) { public HttpServerRequest setExpectMultipart(boolean expect) { synchronized (conn) { checkEnded(); + expectMultipart = expect; if (expect) { if (decoder == null) { String contentType = request.headers().get(HttpHeaderNames.CONTENT_TYPE); @@ -500,10 +502,8 @@ public HttpServerRequest setExpectMultipart(boolean expect) { } @Override - public boolean isExpectMultipart() { - synchronized (conn) { - return decoder != null; - } + public synchronized boolean isExpectMultipart() { + return expectMultipart; } @Override diff --git a/src/main/java/io/vertx/core/http/impl/Http2ServerRequest.java b/src/main/java/io/vertx/core/http/impl/Http2ServerRequest.java index 54681dc0079..a262f288753 100644 --- a/src/main/java/io/vertx/core/http/impl/Http2ServerRequest.java +++ b/src/main/java/io/vertx/core/http/impl/Http2ServerRequest.java @@ -64,6 +64,7 @@ public class Http2ServerRequest extends HttpServerRequestInternal implements Htt private HttpEventHandler eventHandler; private boolean ended; private Handler uploadHandler; + private boolean expectMultipart; private HttpPostRequestDecoder postRequestDecoder; private Handler customFrameHandler; private Handler streamPriorityHandler; @@ -397,6 +398,7 @@ public Future toNetSocket() { public HttpServerRequest setExpectMultipart(boolean expect) { synchronized (stream.conn) { checkEnded(); + expectMultipart = expect; if (expect) { if (postRequestDecoder == null) { String contentType = headersMap.get(HttpHeaderNames.CONTENT_TYPE); @@ -431,7 +433,7 @@ public HttpServerRequest setExpectMultipart(boolean expect) { @Override public boolean isExpectMultipart() { synchronized (stream.conn) { - return postRequestDecoder != null; + return expectMultipart; } } diff --git a/src/test/java/io/vertx/core/http/HttpServerFileUploadTest.java b/src/test/java/io/vertx/core/http/HttpServerFileUploadTest.java index 5438f202786..80c3b691690 100644 --- a/src/test/java/io/vertx/core/http/HttpServerFileUploadTest.java +++ b/src/test/java/io/vertx/core/http/HttpServerFileUploadTest.java @@ -304,6 +304,7 @@ private void testFormUploadFile(String filename, req.endHandler(v -> { MultiMap attrs = req.formAttributes(); attributeCount.set(attrs.size()); + assertTrue(req.isExpectMultipart()); req.response().end(); }); }