Process multipart properties for PartEvent support

Prior to this commit, some properties in the `spring.webflux.multipart`
namespace were ignored for the streaming use case because those were not
supported in streaming mode with `PartEvent`.

As of Spring Framework 6.1, the `max-parts` and
`max-disk-usage-per-part` properties can be supported and this commit
maps those properties accordingly.

Fixes gh-37642
This commit is contained in:
Brian Clozel 2023-11-10 11:36:13 +01:00
parent 7e79d1f3c7
commit 67c5d10051
3 changed files with 13 additions and 5 deletions

View File

@ -78,6 +78,10 @@ public class ReactiveMultipartAutoConfiguration {
map.from(multipartProperties::getMaxHeadersSize)
.asInt(DataSize::toBytes)
.to(partEventHttpMessageReader::setMaxHeadersSize);
map.from(multipartProperties::getMaxDiskUsagePerPart)
.as(DataSize::toBytes)
.to(partEventHttpMessageReader::setMaxPartSize);
map.from(multipartProperties::getMaxParts).to(partEventHttpMessageReader::setMaxParts);
map.from(multipartProperties::getHeadersCharset).to(partEventHttpMessageReader::setHeadersCharset);
}
});

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,7 +37,7 @@ public class ReactiveMultipartProperties {
/**
* Maximum amount of memory allowed per part before it's written to disk. Set to -1 to
* store all contents in memory. Ignored when streaming is enabled.
* store all contents in memory.
*/
private DataSize maxInMemorySize = DataSize.ofKilobytes(256);
@ -49,7 +49,7 @@ public class ReactiveMultipartProperties {
/**
* Maximum amount of disk space allowed per part. Default is -1 which enforces no
* limits. Ignored when streaming is enabled.
* limits.
*/
private DataSize maxDiskUsagePerPart = DataSize.ofBytes(-1);
@ -62,7 +62,7 @@ public class ReactiveMultipartProperties {
/**
* Directory used to store file parts larger than 'maxInMemorySize'. Default is a
* directory named 'spring-multipart' created under the system temporary directory.
* Ignored when streaming is enabled.
* Ignored when using the PartEvent streaming support.
*/
private String fileStorageDirectory;

View File

@ -84,17 +84,21 @@ class ReactiveMultipartAutoConfigurationTests {
void shouldConfigureMultipartPropertiesForPartEventReader() {
this.contextRunner
.withPropertyValues("spring.webflux.multipart.max-in-memory-size=1GB",
"spring.webflux.multipart.max-headers-size=16KB", "spring.webflux.multipart.headers-charset:UTF_16")
"spring.webflux.multipart.max-headers-size=16KB",
"spring.webflux.multipart.max-disk-usage-per-part=3GB", "spring.webflux.multipart.max-parts=7",
"spring.webflux.multipart.headers-charset:UTF_16")
.run((context) -> {
CodecCustomizer customizer = context.getBean(CodecCustomizer.class);
DefaultServerCodecConfigurer configurer = new DefaultServerCodecConfigurer();
customizer.customize(configurer);
PartEventHttpMessageReader partReader = getPartEventReader(configurer);
assertThat(partReader).hasFieldOrPropertyWithValue("maxParts", 7);
assertThat(partReader).hasFieldOrPropertyWithValue("maxHeadersSize",
Math.toIntExact(DataSize.ofKilobytes(16).toBytes()));
assertThat(partReader).hasFieldOrPropertyWithValue("headersCharset", StandardCharsets.UTF_16);
assertThat(partReader).hasFieldOrPropertyWithValue("maxInMemorySize",
Math.toIntExact(DataSize.ofGigabytes(1).toBytes()));
assertThat(partReader).hasFieldOrPropertyWithValue("maxPartSize", DataSize.ofGigabytes(3).toBytes());
});
}