Skip to content

Commit 6fe5652

Browse files
committed
Support non-standard HTTP methods in FrameworkServlet
This commit ensures that HTTP methods not supported by HttpServlet, for instance WebDAV methods, are still supported in FrameworkServlet. Closes gh-29689
1 parent ca68bbc commit 6fe5652

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import java.util.Collection;
2323
import java.util.List;
24+
import java.util.Set;
2425
import java.util.concurrent.Callable;
2526
import java.util.stream.Collectors;
2627

@@ -167,6 +168,12 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
167168
*/
168169
private static final String INIT_PARAM_DELIMITERS = ",; \t\n";
169170

171+
/**
172+
* HTTP methods supported by {@link jakarta.servlet.http.HttpServlet}.
173+
*/
174+
private static final Set<String> HTTP_SERVLET_METHODS = Set.of("DELETE", "HEAD", "GET", "OPTIONS", "POST", "PUT",
175+
"TRACE");
176+
170177

171178
/** ServletContext attribute to find the WebApplicationContext in. */
172179
@Nullable
@@ -866,18 +873,18 @@ public void destroy() {
866873

867874

868875
/**
869-
* Override the parent class implementation in order to intercept PATCH requests.
876+
* Override the parent class implementation in order to intercept requests
877+
* using PATCH or non-standard HTTP methods (WebDAV).
870878
*/
871879
@Override
872880
protected void service(HttpServletRequest request, HttpServletResponse response)
873881
throws ServletException, IOException {
874882

875-
HttpMethod httpMethod = HttpMethod.valueOf(request.getMethod());
876-
if (HttpMethod.PATCH.equals(httpMethod)) {
877-
processRequest(request, response);
883+
if (HTTP_SERVLET_METHODS.contains(request.getMethod())) {
884+
super.service(request, response);
878885
}
879886
else {
880-
super.service(request, response);
887+
processRequest(request, response);
881888
}
882889
}
883890

spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,14 @@ public void mixedInitializerClasses() throws Exception {
875875
assertThat(getServletContext().getAttribute("otherInitialized")).isEqualTo("true");
876876
}
877877

878+
@Test
879+
public void webDavMethod() throws Exception {
880+
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "PROPFIND", "/body.do");
881+
MockHttpServletResponse response = new MockHttpServletResponse();
882+
complexDispatcherServlet.service(request, response);
883+
assertThat(response.getContentAsString()).isEqualTo("body");
884+
}
885+
878886

879887
public static class ControllerFromParent implements Controller {
880888

0 commit comments

Comments
 (0)