Add property to disable HiddenHttpMethodFilter

Closes gh-14030
pull/14008/merge
artsiom 6 years ago committed by Brian Clozel
parent 4bc5535c37
commit d22c3e2787

@ -135,6 +135,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
* @author Stephane Nicoll
* @author Kristine Jetzke
* @author Bruce Brouwer
* @author Artsiom Yudovin
*/
@Configuration
@ConditionalOnWebApplication(type = Type.SERVLET)
@ -153,6 +154,7 @@ public class WebMvcAutoConfiguration {
@Bean
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
@ConditionalOnProperty(prefix = "spring.mvc.hiddenmethod.filter", name = "enabled", matchIfMissing = true)
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new OrderedHiddenHttpMethodFilter();
}

@ -466,6 +466,12 @@
"description": "Whether to enable Spring's HttpPutFormContentFilter.",
"defaultValue": true
},
{
"name": "spring.mvc.hiddenmethod.filter.enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable Spring's HiddenHttpMethodFilter.",
"defaultValue": true
},
{
"name" : "spring.mvc.media-types",
"type" : "java.util.Map<java.lang.String,org.springframework.http.MediaType>",

@ -71,6 +71,7 @@ import org.springframework.web.accept.ParameterContentNegotiationStrategy;
import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.filter.HttpPutFormContentFilter;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerExceptionResolver;
@ -118,6 +119,7 @@ import static org.mockito.Mockito.mock;
* @author Brian Clozel
* @author Eddú Meléndez
* @author Kristine Jetzke
* @author Artsiom Yudovin
*/
public class WebMvcAutoConfigurationTests {
@ -572,6 +574,20 @@ public class WebMvcAutoConfigurationTests {
.doesNotHaveBean(HttpPutFormContentFilter.class));
}
@Test
public void hiddenHttpMethodFilterCanBeDisabled() {
this.contextRunner
.withPropertyValues("spring.mvc.hiddenmethod.filter.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(HiddenHttpMethodFilter.class));
}
@Test
public void hiddenHttpMethodFilterEnabledByDefault() {
this.contextRunner.run((context) -> assertThat(context)
.hasSingleBean(HiddenHttpMethodFilter.class));
}
@Test
public void customConfigurableWebBindingInitializer() {
this.contextRunner

@ -429,6 +429,7 @@ content into your application. Rather, pick only the properties that you need.
spring.mvc.dispatch-options-request=true # Whether to dispatch OPTIONS requests to the FrameworkServlet doService method.
spring.mvc.favicon.enabled=true # Whether to enable resolution of favicon.ico.
spring.mvc.formcontent.putfilter.enabled=true # Whether to enable Spring's HttpPutFormContentFilter.
spring.mvc.hiddenmethod.filter.enabled=true # Whether to enable Spring's HiddenHttpMethodFilter.
spring.mvc.ignore-default-model-on-redirect=true # Whether the content of the "default" model should be ignored during redirect scenarios.
spring.mvc.locale= # Locale to use. By default, this locale is overridden by the "Accept-Language" header.
spring.mvc.locale-resolver=accept-header # Define how the locale should be resolved.

Loading…
Cancel
Save