From 7e23c603c1d5731681b799e145af031237d5ce70 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Tue, 24 Dec 2024 12:04:05 +0100 Subject: [PATCH 1/3] log precondition result on PUT request --- radicale/app/put.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/radicale/app/put.py b/radicale/app/put.py index c1f0eacd..a3961269 100644 --- a/radicale/app/put.py +++ b/radicale/app/put.py @@ -198,15 +198,22 @@ def do_PUT(self, environ: types.WSGIEnviron, base_prefix: str, etag = environ.get("HTTP_IF_MATCH", "") if not item and etag: # Etag asked but no item found: item has been removed + logger.warning("Precondition failed on PUT request for %r (HTTP_IF_MATCH: %s, item not existing)", path, etag) return httputils.PRECONDITION_FAILED if item and etag and item.etag != etag: # Etag asked but item not matching: item has changed + logger.warning("Precondition failed on PUT request for %r (HTTP_IF_MATCH: %s, item has different etag: %s)", path, etag, item.etag) return httputils.PRECONDITION_FAILED + if etag: + logger.debug("Precondition passed on PUT request for %r (HTTP_IF_MATCH: %s, item has etag: %s)", path, etag, item.etag) match = environ.get("HTTP_IF_NONE_MATCH", "") == "*" if item and match: # Creation asked but item found: item can't be replaced + logger.warning("Precondition failed on PUT request for %r (HTTP_IF_NONE_MATCH: *, creation requested but item found with etag: %s)", path, item.etag) return httputils.PRECONDITION_FAILED + if match: + logger.debug("Precondition passed on PUT request for %r (HTTP_IF_NONE_MATCH: *)", path) if (tag != prepared_tag or prepared_write_whole_collection != write_whole_collection): From 0b00218d753f200658c638dae6efcfa4b408892d Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Tue, 24 Dec 2024 12:04:09 +0100 Subject: [PATCH 2/3] log precondition result on PUT request / changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d90d6c91..b4dcea9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Improve: disable fsync during storage verification * Improve: suppress duplicate log lines on startup * Contrib: logwatch config and script +* Improve: log precondition result on PUT request ## 3.3.2 * Fix: debug logging in rights/from_file From 1e8d9eda50e482d84e05bfa19405709735169dc9 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Tue, 24 Dec 2024 12:10:47 +0100 Subject: [PATCH 3/3] fix found by mypy --- radicale/app/put.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radicale/app/put.py b/radicale/app/put.py index a3961269..6e1ba215 100644 --- a/radicale/app/put.py +++ b/radicale/app/put.py @@ -204,7 +204,7 @@ def do_PUT(self, environ: types.WSGIEnviron, base_prefix: str, # Etag asked but item not matching: item has changed logger.warning("Precondition failed on PUT request for %r (HTTP_IF_MATCH: %s, item has different etag: %s)", path, etag, item.etag) return httputils.PRECONDITION_FAILED - if etag: + if item and etag: logger.debug("Precondition passed on PUT request for %r (HTTP_IF_MATCH: %s, item has etag: %s)", path, etag, item.etag) match = environ.get("HTTP_IF_NONE_MATCH", "") == "*"