Merge pull request #37242 from quaff
* pr/37242: Polish "Introduce configuration property for strict servlet compliance" Introduce configuration property for strict servlet compliance Closes gh-37242
This commit is contained in:
commit
e40de41ce0
|
@ -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.
|
||||
|
@ -46,6 +46,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
|||
* @author Greg Turnquist
|
||||
* @author Josh Long
|
||||
* @author Toshiaki Maki
|
||||
* @author Yanming Zhou
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@AutoConfiguration
|
||||
|
@ -72,6 +73,7 @@ public class MultipartAutoConfiguration {
|
|||
public StandardServletMultipartResolver multipartResolver() {
|
||||
StandardServletMultipartResolver multipartResolver = new StandardServletMultipartResolver();
|
||||
multipartResolver.setResolveLazily(this.multipartProperties.isResolveLazily());
|
||||
multipartResolver.setStrictServletCompliance(this.multipartProperties.isStrictServletCompliance());
|
||||
return multipartResolver;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -43,6 +43,7 @@ import org.springframework.util.unit.DataSize;
|
|||
* @author Josh Long
|
||||
* @author Toshiaki Maki
|
||||
* @author Stephane Nicoll
|
||||
* @author Yanming Zhou
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.servlet.multipart", ignoreUnknownFields = false)
|
||||
|
@ -79,6 +80,12 @@ public class MultipartProperties {
|
|||
*/
|
||||
private boolean resolveLazily = false;
|
||||
|
||||
/**
|
||||
* Whether to resolve the multipart request strictly comply with the Servlet
|
||||
* specification, only to be used for "multipart/form-data" requests.
|
||||
*/
|
||||
private boolean strictServletCompliance = false;
|
||||
|
||||
public boolean getEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
@ -127,6 +134,14 @@ public class MultipartProperties {
|
|||
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
|
||||
|
|
|
@ -64,6 +64,7 @@ import static org.mockito.Mockito.mock;
|
|||
* @author Josh Long
|
||||
* @author Ivan Sopov
|
||||
* @author Toshiaki Maki
|
||||
* @author Yanming Zhou
|
||||
*/
|
||||
@DirtiesUrlFactories
|
||||
class MultipartAutoConfigurationTests {
|
||||
|
@ -174,6 +175,17 @@ class MultipartAutoConfigurationTests {
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue