diff --git a/java/org/apache/catalina/servlets/DefaultServlet.java b/java/org/apache/catalina/servlets/DefaultServlet.java index fd9710ff19ae..7ac3a29b3fb3 100644 --- a/java/org/apache/catalina/servlets/DefaultServlet.java +++ b/java/org/apache/catalina/servlets/DefaultServlet.java @@ -726,6 +726,10 @@ protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws WebResource resource = resources.getResource(path); + if (!checkIfHeaders(req, resp, resource)) { + return; + } + if (resource.exists()) { if (resource.delete()) { resp.setStatus(HttpServletResponse.SC_NO_CONTENT); @@ -735,7 +739,6 @@ protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } - } diff --git a/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java b/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java index a71e3e743c4d..ceb020c190f1 100644 --- a/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java +++ b/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java @@ -258,6 +258,35 @@ public static Collection parameters() { null, null, null, Boolean.FALSE, SC_400 }); parameterSets.add(new Object[] { useStrongEtag, Task.PUT_NEW_TXT, EtagPrecondition.INVALID_ALL_PLUS_OTHER, null, null, null, null, null, Boolean.FALSE, SC_400 }); + + // DELETE TESTS + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_EXIST_TXT, null, null, null, null, null, null, + Boolean.FALSE, SC_204 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_EXIST_TXT, EtagPrecondition.ALL, null, null, null, null, null, + Boolean.FALSE, SC_204 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_EXIST_TXT, EtagPrecondition.EXACTLY, null, null, null, null, null, + Boolean.FALSE, useStrongEtag.booleanValue() ? SC_204 : SC_412 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_EXIST_TXT, EtagPrecondition.IN, null, null, null, null, null, + Boolean.FALSE, useStrongEtag.booleanValue() ? SC_204 : SC_412 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_EXIST_TXT, EtagPrecondition.NOT_IN, null, null, null, null, null, + Boolean.FALSE, SC_412 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_EXIST_TXT, EtagPrecondition.INVALID, null, null, null, null, null, + Boolean.FALSE, SC_400 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_EXIST_TXT, EtagPrecondition.INVALID_ALL_PLUS_OTHER, null, null, null, null, null, + Boolean.FALSE, SC_400 }); + + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_NOT_EXIST_TXT, null, null, null, null, null, null, + Boolean.FALSE, SC_404 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.ALL, null, null, null, null, null, + Boolean.FALSE, SC_412 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.IN, null, null, null, null, null, + Boolean.FALSE, SC_412 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.NOT_IN, null, null, null, null, null, + Boolean.FALSE, SC_412 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.INVALID, null, null, null, null, null, + Boolean.FALSE, SC_400 }); + parameterSets.add(new Object[] { useStrongEtag, Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.INVALID_ALL_PLUS_OTHER, null, null, null, null, null, + Boolean.FALSE, SC_400 }); } return parameterSets; @@ -270,6 +299,7 @@ public static Collection parameters() { private static Integer SC_206 = Integer.valueOf(HttpServletResponse.SC_PARTIAL_CONTENT); private static Integer SC_304 = Integer.valueOf(HttpServletResponse.SC_NOT_MODIFIED); private static Integer SC_400 = Integer.valueOf(HttpServletResponse.SC_BAD_REQUEST); + private static Integer SC_404 = Integer.valueOf(HttpServletResponse.SC_NOT_FOUND); private static Integer SC_412 = Integer.valueOf(HttpServletResponse.SC_PRECONDITION_FAILED); @@ -296,10 +326,6 @@ private enum Task { PUT_NEW_TXT(HTTP_METHOD.PUT, "/put_new.txt"), DELETE_EXIST_TXT(HTTP_METHOD.DELETE, "/delete_exist.txt"), - DELETE_EXIST1_TXT(HTTP_METHOD.DELETE, "/delete_exist1.txt"), - DELETE_EXIST2_TXT(HTTP_METHOD.DELETE, "/delete_exist2.txt"), - DELETE_EXIST3_TXT(HTTP_METHOD.DELETE, "/delete_exist3.txt"), - DELETE_EXIST4_TXT(HTTP_METHOD.DELETE, "/delete_exist4.txt"), DELETE_NOT_EXIST_TXT(HTTP_METHOD.DELETE, "/delete_404.txt"); HTTP_METHOD m; @@ -481,22 +507,6 @@ public void setUp() throws Exception { Files.write(Path.of(tempDocBase.getAbsolutePath(), "delete_exist.txt"), "delete_exist_v0".getBytes(), StandardOpenOption.CREATE); Path.of(tempDocBase.getAbsolutePath(), "delete_exist.txt").toFile().setLastModified(lastModified); - - Files.write(Path.of(tempDocBase.getAbsolutePath(), "delete_exist1.txt"), "delete_exist1_v0".getBytes(), - StandardOpenOption.CREATE); - Path.of(tempDocBase.getAbsolutePath(), "delete_exist1.txt").toFile().setLastModified(lastModified); - - Files.write(Path.of(tempDocBase.getAbsolutePath(), "delete_exist2.txt"), "delete_exist2_v0".getBytes(), - StandardOpenOption.CREATE); - Path.of(tempDocBase.getAbsolutePath(), "delete_exist2.txt").toFile().setLastModified(lastModified); - - Files.write(Path.of(tempDocBase.getAbsolutePath(), "delete_exist3.txt"), "delete_exist3_v0".getBytes(), - StandardOpenOption.CREATE); - Path.of(tempDocBase.getAbsolutePath(), "delete_exist3.txt").toFile().setLastModified(lastModified); - - Files.write(Path.of(tempDocBase.getAbsolutePath(), "delete_exist4.txt"), "delete_exist4_v0".getBytes(), - StandardOpenOption.CREATE); - Path.of(tempDocBase.getAbsolutePath(), "delete_exist4.txt").toFile().setLastModified(lastModified); } }