Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -46,6 +46,7 @@
* @author Greg Turnquist
* @author Josh Long
* @author Toshiaki Maki
* @author Yanming Zhou
* @since 2.0.0
*/
@AutoConfiguration
Expand All @@ -72,6 +73,7 @@ public MultipartConfigElement multipartConfigElement() {
public StandardServletMultipartResolver multipartResolver() {
StandardServletMultipartResolver multipartResolver = new StandardServletMultipartResolver();
multipartResolver.setResolveLazily(this.multipartProperties.isResolveLazily());
multipartResolver.setStrictServletCompliance(this.multipartProperties.isStrictServletCompliance());
return multipartResolver;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 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.
Expand Down Expand Up @@ -43,6 +43,7 @@
* @author Josh Long
* @author Toshiaki Maki
* @author Stephane Nicoll
* @author Yanming Zhou
* @since 2.0.0
*/
@ConfigurationProperties(prefix = "spring.servlet.multipart", ignoreUnknownFields = false)
Expand Down Expand Up @@ -79,6 +80,12 @@ public class MultipartProperties {
*/
private boolean resolveLazily = false;

/**
* Whether to resolve the multipart request strictly comply with the Servlet specification,
* only kicking in for "multipart/form-data" requests.
*/
private boolean strictServletCompliance = false;

public boolean getEnabled() {
return this.enabled;
}
Expand Down Expand Up @@ -127,6 +134,14 @@ public void setResolveLazily(boolean resolveLazily) {
this.resolveLazily = resolveLazily;
}

public boolean isStrictServletCompliance() {
return this.strictServletCompliance;
}

public void setStrictServletCompliance(boolean strictServletCompliance) {
this.strictServletCompliance = strictServletCompliance;
}

/**
* Create a new {@link MultipartConfigElement} using the properties.
* @return a new {@link MultipartConfigElement} configured using there properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
* @author Josh Long
* @author Ivan Sopov
* @author Toshiaki Maki
* @author Yanming Zhou
*/
@DirtiesUrlFactories
class MultipartAutoConfigurationTests {
Expand Down Expand Up @@ -174,6 +175,17 @@ void configureResolveLazily() {
assertThat(multipartResolver).hasFieldOrPropertyWithValue("resolveLazily", true);
}

@Test
void configureStrictServletCompliance() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
TestPropertyValues.of("spring.servlet.multipart.strict-servlet-compliance=true").applyTo(this.context);
this.context.register(WebServerWithNothing.class, BaseConfiguration.class);
this.context.refresh();
StandardServletMultipartResolver multipartResolver = this.context
.getBean(StandardServletMultipartResolver.class);
assertThat(multipartResolver).hasFieldOrPropertyWithValue("strictServletCompliance", true);
}

@Test
void configureMultipartProperties() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
Expand Down