From 024ef3286d1c5a5434263db17b0097a293f11baa Mon Sep 17 00:00:00 2001 From: xjusko Date: Mon, 6 Nov 2023 15:37:10 +0100 Subject: [PATCH] [UNDERTOW-2319] Move io.undertow.multipart.minsize property to UndertowOptions --- .../src/main/java/io/undertow/UndertowOptions.java | 14 ++++++++++++++ .../handlers/form/MultiPartParserDefinition.java | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/undertow/UndertowOptions.java b/core/src/main/java/io/undertow/UndertowOptions.java index edafbf036f..0cfef791c0 100644 --- a/core/src/main/java/io/undertow/UndertowOptions.java +++ b/core/src/main/java/io/undertow/UndertowOptions.java @@ -422,6 +422,20 @@ public class UndertowOptions { */ public static final Option MAX_RST_FRAMES_PER_WINDOW = Option.simple(UndertowOptions.class, "MAX_RST_STREAMS_PER_TIME_WINDOW", Integer.class); + /** + * Proposed default minimum size for storing content in memory before persisting to disk. + * The default value for {@code MEMORY_STORAGE_THRESHOLD} is 16 KB (16384 bytes). + */ + public static final long DEFAULT_MEMORY_STORAGE_THRESHOLD = 0x4000; + + /** + * The minimum size in bytes for storing content in memory before persisting to disk. If the file content exceeds + * the specified file size threshold and the filename is not specified in the form, the content will be stored + * in memory as long as its size is less than or equal to this minimum size, after which it will be persisted to disk. + */ + public static final Option MEMORY_STORAGE_THRESHOLD = Option.simple(UndertowOptions.class, "MEMORY_STORAGE_THRESHOLD", Long.class); + + private UndertowOptions() { } diff --git a/core/src/main/java/io/undertow/server/handlers/form/MultiPartParserDefinition.java b/core/src/main/java/io/undertow/server/handlers/form/MultiPartParserDefinition.java index 0655f3758c..966c9ab541 100644 --- a/core/src/main/java/io/undertow/server/handlers/form/MultiPartParserDefinition.java +++ b/core/src/main/java/io/undertow/server/handlers/form/MultiPartParserDefinition.java @@ -82,7 +82,7 @@ public class MultiPartParserDefinition implements FormParserFactory.ParserDefini * The threshold of form field size to persist to disk. * It takes effect only for the form fields which do not have filename specified. */ - private long fieldSizeThreshold = MINSIZE; + private long fieldSizeThreshold; public MultiPartParserDefinition() { tempFileLocation = Paths.get(System.getProperty("java.io.tmpdir")); @@ -101,6 +101,7 @@ public FormDataParser create(final HttpServerExchange exchange) { UndertowLogger.REQUEST_LOGGER.debugf("Could not find boundary in multipart request with ContentType: %s, multipart data will not be available", mimeType); return null; } + fieldSizeThreshold = exchange.getConnection().getUndertowOptions().get(UndertowOptions.MEMORY_STORAGE_THRESHOLD, UndertowOptions.DEFAULT_MEMORY_STORAGE_THRESHOLD); final MultiPartUploadHandler parser = new MultiPartUploadHandler(exchange, boundary, maxIndividualFileSize, fileSizeThreshold, defaultEncoding, fieldSizeThreshold); exchange.addExchangeCompleteListener(new ExchangeCompletionListener() { @Override