Skip to content

Commit d22c3e2

Browse files
artsiombclozel
authored andcommitted
Add property to disable HiddenHttpMethodFilter
Closes gh-14030
1 parent 4bc5535 commit d22c3e2

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
* @author Stephane Nicoll
136136
* @author Kristine Jetzke
137137
* @author Bruce Brouwer
138+
* @author Artsiom Yudovin
138139
*/
139140
@Configuration
140141
@ConditionalOnWebApplication(type = Type.SERVLET)
@@ -153,6 +154,7 @@ public class WebMvcAutoConfiguration {
153154

154155
@Bean
155156
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
157+
@ConditionalOnProperty(prefix = "spring.mvc.hiddenmethod.filter", name = "enabled", matchIfMissing = true)
156158
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
157159
return new OrderedHiddenHttpMethodFilter();
158160
}

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@
466466
"description": "Whether to enable Spring's HttpPutFormContentFilter.",
467467
"defaultValue": true
468468
},
469+
{
470+
"name": "spring.mvc.hiddenmethod.filter.enabled",
471+
"type": "java.lang.Boolean",
472+
"description": "Whether to enable Spring's HiddenHttpMethodFilter.",
473+
"defaultValue": true
474+
},
469475
{
470476
"name" : "spring.mvc.media-types",
471477
"type" : "java.util.Map<java.lang.String,org.springframework.http.MediaType>",

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
7272
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
7373
import org.springframework.web.context.request.ServletWebRequest;
74+
import org.springframework.web.filter.HiddenHttpMethodFilter;
7475
import org.springframework.web.filter.HttpPutFormContentFilter;
7576
import org.springframework.web.servlet.HandlerAdapter;
7677
import org.springframework.web.servlet.HandlerExceptionResolver;
@@ -118,6 +119,7 @@
118119
* @author Brian Clozel
119120
* @author Eddú Meléndez
120121
* @author Kristine Jetzke
122+
* @author Artsiom Yudovin
121123
*/
122124
public class WebMvcAutoConfigurationTests {
123125

@@ -572,6 +574,20 @@ public void httpPutFormContentFilterCanBeDisabled() {
572574
.doesNotHaveBean(HttpPutFormContentFilter.class));
573575
}
574576

577+
@Test
578+
public void hiddenHttpMethodFilterCanBeDisabled() {
579+
this.contextRunner
580+
.withPropertyValues("spring.mvc.hiddenmethod.filter.enabled=false")
581+
.run((context) -> assertThat(context)
582+
.doesNotHaveBean(HiddenHttpMethodFilter.class));
583+
}
584+
585+
@Test
586+
public void hiddenHttpMethodFilterEnabledByDefault() {
587+
this.contextRunner.run((context) -> assertThat(context)
588+
.hasSingleBean(HiddenHttpMethodFilter.class));
589+
}
590+
575591
@Test
576592
public void customConfigurableWebBindingInitializer() {
577593
this.contextRunner

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ content into your application. Rather, pick only the properties that you need.
429429
spring.mvc.dispatch-options-request=true # Whether to dispatch OPTIONS requests to the FrameworkServlet doService method.
430430
spring.mvc.favicon.enabled=true # Whether to enable resolution of favicon.ico.
431431
spring.mvc.formcontent.putfilter.enabled=true # Whether to enable Spring's HttpPutFormContentFilter.
432+
spring.mvc.hiddenmethod.filter.enabled=true # Whether to enable Spring's HiddenHttpMethodFilter.
432433
spring.mvc.ignore-default-model-on-redirect=true # Whether the content of the "default" model should be ignored during redirect scenarios.
433434
spring.mvc.locale= # Locale to use. By default, this locale is overridden by the "Accept-Language" header.
434435
spring.mvc.locale-resolver=accept-header # Define how the locale should be resolved.

0 commit comments

Comments
 (0)