Xuanwo opened a new pull request, #8944:
URL: https://github.com/apache/opendal/pull/8944

   # Which issue does this PR close?
   
   Closes #8940.
   
   # Rationale for this change
   
   WebDAV servers such as Apache HTTP Server (`mod_dav` / `mod_dav_fs`) emit 
weak ETags (`W/"..."`) for recently modified files and later upgrade them to 
strong ETags. Previously, `opendal-service-webdav` failed two conditional 
operations when given a weak ETag:
   
   1. `delete_with(path).if_match(weak_etag)` sent HTTP `If-Match: W/"..."`, 
which requires strong comparison under RFC 9110 §13.1.1 and always fails with 
HTTP 412 (`ConditionNotMatch`).
   2. `write_with(path, data).if_none_match(weak_etag)` only sent HTTP 
`If-None-Match: W/"..."`. Apache `mod_dav` evaluates `If-None-Match` with 
strong comparison on non-GET/HEAD requests, allowing an overwrite when the weak 
ETag matched the existing resource.
   
   Using an untagged WebDAV `If` header (`If: ([W/"..."])`) also fails on 
nested paths during `DELETE` (or new-file `PUT`) because RFC 4918 §10.4.2 
applies no-tag lists to every resource checked by the method, including parent 
collections. Encoding weak ETag preconditions as a tagged-list WebDAV `If` 
header (`If: <url> (...)`) scopes the check to the target resource URI, and 
trimming trailing slashes from `endpoint` keeps the tagged `<url>` aligned with 
the canonical request URI.
   
   # What changes are included in this PR?
   
   - Add `apply_etag_preconditions` and `validate_weak_etag` in 
`core/services/webdav/src/core.rs` and wire them into both `webdav_put` and 
`webdav_delete`:
     - Strong ETags and `*` continue to use `If-Match` / `If-None-Match`.
     - Weak `if_match` on PUT and DELETE uses `If: <url> ([W/"..."])` (omitting 
`If-Match`).
     - Weak `if_none_match` on PUT sends both `If-None-Match: W/"..."` and `If: 
<url> (Not [W/"..."])`.
     - Combined weak `if_match` and weak `if_none_match` are merged into a 
single tagged `If` header.
     - Reject malformed weak ETags (including embedded `]`) with 
`ErrorKind::ConfigInvalid`.
   - Trim trailing `/` characters from `WebdavCore.endpoint` in 
`core/services/webdav/src/backend.rs` so request URLs and tagged `If: <url>` 
targets do not contain duplicate slashes when `endpoint` has a trailing slash.
   - Add unit tests in `core/services/webdav/src/backend.rs` covering 
strong/weak `if_match`, `if_none_match`, `if_not_exists`, combined weak 
preconditions, trailing-slash endpoint normalization, and invalid weak ETag 
rejection.
   - Update `core/services/webdav/src/docs.md` and 
`core/services/webdav/README.md` to document the conditional PUT and DELETE 
header behavior and updated Apache `mod_dav_fs` matrix.
   
   # Are there any user-facing changes?
   
   - `delete_with(...).if_match(weak_etag)` and 
`write_with(...).if_none_match(weak_etag)` now enforce weak ETag preconditions 
on WebDAV servers that support RFC 4918 `If` headers (such as Apache 
`mod_dav_fs`), including on nested paths and endpoints configured with a 
trailing slash.
   - Malformed weak ETags (including weak ETags containing `]`) now fail 
locally with `ErrorKind::ConfigInvalid` on both PUT and DELETE.
   - Updated WebDAV service documentation in `core/services/webdav/src/docs.md` 
and `core/services/webdav/README.md`.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: High
   - Role: Reproduced both weak-ETag failures against a live Apache HTTP Server 
2.4 (`mod_dav_fs`) instance before implementing the fix, authored the tagged 
WebDAV `If` header logic, trailing-slash endpoint normalization, unit tests, 
and documentation updates, and verified the fix against live Apache 2.4 
(`mod_dav_fs`) and `dav-server` (`fixtures/webdav/dav-server`). Servers that do 
not evaluate RFC 4918 tagged `If` headers (such as `dav-server` or SabreDAV) 
continue to use the standard `If-None-Match` header for weak `if_none_match` 
and reject weak `if_match`, consistent with the documented server matrix.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to