Skip to content

Feature Request: Preserve file modification time on WebDAV upload via X-OC-MTime header #1569

Description

@yan12125

The issue description is generated by Claude and reviewed/modified by me

Summary

When uploading files to a WebDAV server, Material Files does not preserve the original file modification time (mtime). The server receives PROPFIND and PUT requests, but no mtime-setting mechanism is used. This can be addressed by sending the X-OC-MTime request header alongside PUT.

Why PROPPATCH on getlastmodified does not work

This is a plausible approach. However, RFC 4918 §15.7 specifies that {DAV:}getlastmodified "SHOULD be protected because some clients may rely on the value for appropriate caching behavior, or on the value of the Last-Modified header to which this property is linked." (RFC 4918 §15.7)

In practice, most WebDAV servers implement this recommendation and reject PROPPATCH on getlastmodified with 403 Forbidden. Apache mod_dav, sabre/dav (sabre/dav issue #1277), and others all protect this property by default.

The X-OC-MTime header

Specification

The X-OC-MTime header is a WebDAV extension for setting resource modification time during PUT. It is documented in the ownCloud developer API reference:

Request header: X-OC-Mtime: <unix-timestamp> — an integer Unix timestamp (seconds since epoch) sent with a PUT request.
Response header: X-OC-Mtime: accepted — returned by the server if the mtime was successfully applied.

(ownCloud WebDAV API reference — Upload File)

Example from the ownCloud documentation:

PUT /dav/spaces/.../test.txt HTTP/1.1
X-OC-Mtime: 1692369418
...

HTTP/1.1 204 No Content
X-Oc-Mtime: accepted
Last-Modified: Fri, 18 Aug 2023 14:36:58 +0000

Server support

The header is now supported by a range of WebDAV servers:

Server Source
ownCloud ownCloud WebDAV API reference
Nextcloud Nextcloud WebDAV API
OpenCloud OpenCloud WebDAV API docs
Apache mod_dav (trunk/2.5) New DavHonorMtimeHeader directive — commit 2d92bae, mod_dav docs
rclone serve webdav rclone WebDAV docs
Fastmail Files rclone WebDAV docs for Fastmail Files
SFTPGo SFTPGo commit

Client support

Existing WebDAV clients that send X-OC-MTime include the Nextcloud desktop client, rclone (when vendor is set to owncloud, nextcloud, or fastmail), and Cyberduck / Mountain Duck.

Proposed behavior

When uploading a file to a WebDAV server, Material Files should include the X-OC-MTime header in the PUT request with the source file's modification time as an integer Unix timestamp in seconds:

X-OC-MTime: 1718000000

If the server responds with X-OC-MTime: accepted, the mtime was successfully applied. If the header is absent from the response, it can be silently ignored. Servers that do not recognize the header will ignore it, so sending it unconditionally is safe.

Scope

This request covers PUT only. MOVE and COPY operations are out of scope, as X-OC-MTime is not defined for those methods in existing implementations either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions