Skip to content

Commit

Permalink
Support non-standard HTTP methods in FrameworkServlet
Browse files Browse the repository at this point in the history
This commit ensures that HTTP methods not supported by HttpServlet, for
instance WebDAV methods, are still supported in FrameworkServlet.

Closes spring-projectsgh-29689
  • Loading branch information
poutsma authored and mdeinum committed Jun 29, 2023
1 parent 29a6157 commit e97b7a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String> HTTP_SERVLET_METHODS = Set.of("DELETE", "HEAD", "GET", "OPTIONS", "POST", "PUT",
"TRACE");


/** ServletContext attribute to find the WebApplicationContext in. */
@Nullable
Expand Down Expand Up @@ -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);
}
}

Expand Down
Expand Up @@ -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 {

Expand Down

0 comments on commit e97b7a8

Please sign in to comment.