Skip to content

Commit

Permalink
Fix default unit for multipart properties
Browse files Browse the repository at this point in the history
This commit fixes a regression that wrongly changed the default unit of
multipart properties from bytes to megabytes.

Closes spring-projectsgh-15162
  • Loading branch information
snicoll committed Nov 15, 2018
1 parent 2f4325d commit c1b1f14
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.boot.convert.DataSizeUnit;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;

/**
* Properties to be used in configuring a {@link MultipartConfigElement}.
Expand Down Expand Up @@ -63,13 +61,11 @@ public class MultipartProperties {
/**
* Max file size.
*/
@DataSizeUnit(DataUnit.MEGABYTES)
private DataSize maxFileSize = DataSize.ofMegabytes(1);

/**
* Max request size.
*/
@DataSizeUnit(DataUnit.MEGABYTES)
private DataSize maxRequestSize = DataSize.ofMegabytes(10);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,37 @@ public void configureResolveLazily() {
assertThat(multipartResolver).hasFieldOrPropertyWithValue("resolveLazily", true);
}

@Test
public void configureMultipartProperties() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
TestPropertyValues
.of("spring.servlet.multipart.max-file-size=2048KB",
"spring.servlet.multipart.max-request-size=15MB")
.applyTo(this.context);
this.context.register(WebServerWithNothing.class, BaseConfiguration.class);
this.context.refresh();
MultipartConfigElement multipartConfigElement = this.context
.getBean(MultipartConfigElement.class);
assertThat(multipartConfigElement.getMaxFileSize()).isEqualTo(2048 * 1024);
assertThat(multipartConfigElement.getMaxRequestSize())
.isEqualTo(15 * 1024 * 1024);
}

@Test
public void configureMultipartPropertiesWithRawLongValues() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
TestPropertyValues
.of("spring.servlet.multipart.max-file-size=512",
"spring.servlet.multipart.max-request-size=2048")
.applyTo(this.context);
this.context.register(WebServerWithNothing.class, BaseConfiguration.class);
this.context.refresh();
MultipartConfigElement multipartConfigElement = this.context
.getBean(MultipartConfigElement.class);
assertThat(multipartConfigElement.getMaxFileSize()).isEqualTo(512);
assertThat(multipartConfigElement.getMaxRequestSize()).isEqualTo(2048);
}

private void verify404() throws Exception {
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
ClientHttpRequest request = requestFactory.createRequest(new URI(
Expand Down

0 comments on commit c1b1f14

Please sign in to comment.