You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2024/12/13 08:43:41 UTC
(tomcat) branch 11.0.x updated: Add precondition support to DELETE requests
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new d288f51274 Add precondition support to DELETE requests
d288f51274 is described below
commit d288f51274e2fe5e77a93b3c6301746016e9105e
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Dec 13 08:42:34 2024 +0000
Add precondition support to DELETE requests
---
.../apache/catalina/servlets/DefaultServlet.java | 5 ++-
...efaultServletRfc9110Section13Parameterized.java | 50 +++++++++++++---------
2 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/java/org/apache/catalina/servlets/DefaultServlet.java b/java/org/apache/catalina/servlets/DefaultServlet.java
index 0fea19b8fb..238f8f11e5 100644
--- a/java/org/apache/catalina/servlets/DefaultServlet.java
+++ b/java/org/apache/catalina/servlets/DefaultServlet.java
@@ -716,6 +716,10 @@ public class DefaultServlet extends HttpServlet {
WebResource resource = resources.getResource(path);
+ if (!checkIfHeaders(req, resp, resource)) {
+ return;
+ }
+
if (resource.exists()) {
if (resource.delete()) {
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
@@ -725,7 +729,6 @@ public class DefaultServlet extends HttpServlet {
} 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 a71e3e743c..ceb020c190 100644
--- a/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java
+++ b/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java
@@ -258,6 +258,35 @@ public class TestDefaultServletRfc9110Section13Parameterized extends TomcatBaseT
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 class TestDefaultServletRfc9110Section13Parameterized extends TomcatBaseT
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 @@ public class TestDefaultServletRfc9110Section13Parameterized extends TomcatBaseT
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 class TestDefaultServletRfc9110Section13Parameterized extends TomcatBaseT
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);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org