Skip to content

Commit

Permalink
Merge pull request #1533 from xjusko/UNDERTOW-2319
Browse files Browse the repository at this point in the history
[UNDERTOW-2319] Move io.undertow.multipart.minsize property to UndertowOptions
baranowb authored Nov 27, 2024
2 parents 56615a7 + d31127a commit 29fc22c
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 14 additions & 0 deletions core/src/main/java/io/undertow/UndertowOptions.java
Original file line number Diff line number Diff line change
@@ -448,6 +448,20 @@ public class UndertowOptions {
*/
public static final Option<Integer> 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 <i>file size threshold</i> and the <i>filename</i> 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<Long> MEMORY_STORAGE_THRESHOLD = Option.simple(UndertowOptions.class, "MEMORY_STORAGE_THRESHOLD", Long.class);


/**
* Configure a read timeout for a web socket, in milliseconds. If its present it will override {@link org.xnio.Options.READ_TIMEOUT}. If the given amount of time elapses without
* a successful read taking place, the socket's next read will throw a {@link ReadTimeoutException}.
Original file line number Diff line number Diff line change
@@ -62,11 +62,6 @@ public class MultiPartParserDefinition implements FormParserFactory.ParserDefini


public static final String MULTIPART_FORM_DATA = "multipart/form-data";
/**
* Proposed default MINSIZE as 16 KB for content in memory before persisting to disk if file content exceeds
* {@link #fileSizeThreshold} and the <i>filename</i> is not specified in the form.
*/
private static final long MINSIZE = Long.getLong("io.undertow.multipart.minsize", 0x4000);

private Executor executor;

@@ -82,7 +77,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 <i>filename</i> specified.
*/
private long fieldSizeThreshold = MINSIZE;
private long fieldSizeThreshold;

public MultiPartParserDefinition() {
tempFileLocation = Paths.get(System.getProperty("java.io.tmpdir"));
@@ -101,6 +96,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

0 comments on commit 29fc22c

Please sign in to comment.