diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java index af706c2e1243..25cf390494f2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.concurrent.Callable; import java.util.stream.Collectors; @@ -167,6 +168,12 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic */ private static final String INIT_PARAM_DELIMITERS = ",; \t\n"; + /** + * HTTP methods supported by {@link jakarta.servlet.http.HttpServlet}. + */ + private static final Set HTTP_SERVLET_METHODS = Set.of("DELETE", "HEAD", "GET", "OPTIONS", "POST", "PUT", + "TRACE"); + /** ServletContext attribute to find the WebApplicationContext in. */ @Nullable @@ -866,18 +873,18 @@ public void destroy() { /** - * Override the parent class implementation in order to intercept PATCH requests. + * Override the parent class implementation in order to intercept requests + * using PATCH or non-standard HTTP methods (WebDAV). */ @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - HttpMethod httpMethod = HttpMethod.valueOf(request.getMethod()); - if (HttpMethod.PATCH.equals(httpMethod)) { - processRequest(request, response); + if (HTTP_SERVLET_METHODS.contains(request.getMethod())) { + super.service(request, response); } else { - super.service(request, response); + processRequest(request, response); } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java index 595046a04746..8937ea0e1e3e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java @@ -875,6 +875,14 @@ public void mixedInitializerClasses() throws Exception { assertThat(getServletContext().getAttribute("otherInitialized")).isEqualTo("true"); } + @Test + public void webDavMethod() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "PROPFIND", "/body.do"); + MockHttpServletResponse response = new MockHttpServletResponse(); + complexDispatcherServlet.service(request, response); + assertThat(response.getContentAsString()).isEqualTo("body"); + } + public static class ControllerFromParent implements Controller {