Commit 9f17fe44 authored by Phillip Webb's avatar Phillip Webb

Merge pull request #4300 from bohuslav-burghardt/configurable-trace-options-request-handling

* pr/4300:
  Make OPTIONS/TRACE request handling configurable
parents a8b23f9d 88cf6542
......@@ -91,6 +91,10 @@ public class DispatcherServletAutoConfiguration {
@Bean(name = DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)
public DispatcherServlet dispatcherServlet() {
DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setDispatchOptionsRequest(
this.webMvcProperties.isDispatchOptionsRequest());
dispatcherServlet.setDispatchTraceRequest(
this.webMvcProperties.isDispatchTraceRequest());
dispatcherServlet.setThrowExceptionIfNoHandlerFound(
this.webMvcProperties.isThrowExceptionIfNoHandlerFound());
return dispatcherServlet;
......
......@@ -51,6 +51,16 @@ public class WebMvcProperties {
*/
private String dateFormat;
/**
* Dispatch TRACE requests to the FrameworkServlet doService method.
*/
private boolean dispatchTraceRequest = false;
/**
* Dispatch OPTIONS requests to the FrameworkServlet doService method.
*/
private boolean dispatchOptionsRequest = false;
/**
* If the content of the "default" model should be ignored during redirect scenarios.
*/
......@@ -121,6 +131,22 @@ public class WebMvcProperties {
this.mediaTypes = mediaTypes;
}
public boolean isDispatchOptionsRequest() {
return this.dispatchOptionsRequest;
}
public void setDispatchOptionsRequest(boolean dispatchOptionsRequest) {
this.dispatchOptionsRequest = dispatchOptionsRequest;
}
public boolean isDispatchTraceRequest() {
return this.dispatchTraceRequest;
}
public void setDispatchTraceRequest(boolean dispatchTraceRequest) {
this.dispatchTraceRequest = dispatchTraceRequest;
}
public Async getAsync() {
return this.async;
}
......
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2015 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.
......@@ -155,10 +155,18 @@ public class DispatcherServletAutoConfigurationTests {
DispatcherServletAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mvc.throw-exception-if-no-handler-found:true");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mvc.dispatch-options-request:true");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mvc.dispatch-trace-request:true");
this.context.refresh();
DispatcherServlet bean = this.context.getBean(DispatcherServlet.class);
assertEquals(true, new DirectFieldAccessor(bean)
.getPropertyValue("throwExceptionIfNoHandlerFound"));
assertEquals(true,
new DirectFieldAccessor(bean).getPropertyValue("dispatchOptionsRequest"));
assertEquals(true,
new DirectFieldAccessor(bean).getPropertyValue("dispatchTraceRequest"));
}
@Configuration
......
......@@ -302,7 +302,9 @@ content into your application; rather pick only the properties that you need.
# SPRING MVC ({sc-spring-boot-autoconfigure}/web/WebMvcProperties.{sc-ext}[WebMvcProperties])
spring.mvc.async.request-timeout= # Amount of time (in milliseconds) before asynchronous request handling times out.
spring.mvc.date-format= # Date format to use. For instance `dd/MM/yyyy`
spring.mvc.date-format= # Date format to use. For instance `dd/MM/yyyy`.
spring.mvc.dispatch-trace-request=false # Dispatch TRACE requests to the FrameworkServlet doService method.
spring.mvc.dispatch-options-request=false # Dispatch OPTIONS requests to the FrameworkServlet doService method.
spring.mvc.favicon.enabled=true # Enable resolution of favicon.ico.
spring.mvc.ignore-default-model-on-redirect=true # If the content of the "default" model should be ignored during redirect scenarios.
spring.mvc.locale= # Locale to use.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment