Skip to content

Conversation

leo9800
Copy link

@leo9800 leo9800 commented Sep 4, 2025

WebDAV RFCs did not specify a standard approach to set modification time for files or directory on the server, this feature enables better presevation of file metadata when uploading.

as a compensation, OwnCloud (now known as NextCloud) proposed a X-OC-Mtime header which contains UNIX timestamp of mtime with file-modifying methods (e.g. PUT) which implements the feature above as a extension to the standard.

this patch allows apache to optionally honor the X-OC-Mtime header and set mtime accordingly if DavHonorMtimeHeader On is set.

@leo9800 leo9800 marked this pull request as ready for review September 6, 2025 19:56
Copy link
Collaborator

@notroj notroj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting feature. Are you aware of any standardisation effort for that header?

status = apr_file_mtime_set(resource->info->pathname, mtime, pool);

if (status != APR_SUCCESS) {
return dav_new_error(pool, HTTP_BAD_REQUEST, 0, status, "Could not set mtime.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get this far this is likely not a client error so this should be mapped to something appropriate rather than a 400. Or default to 500?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually i was a bit unsure whether 4xx or 5xx should be returned in such case. despite most invalid patterns has already being sanitized in dav_parse_mtime, including:

  • non-digits, e.g. nonsense bytes
  • negatives, e.g. -123123123
  • non-decimal, e.g. 0xa0b1
  • empty strings
  • overflowing

while apr_file_mtime_set may still fail, in most cases it is clear that a 500 should be returned, e.g. kernel VFS failed to respond utime syscall. but i was wondering if there is any possibility that an invalid user input fails apr_file_mtime_set where 400 should be returned.

as of now I would return a 500 in such cases instead of 400.

@leo9800
Copy link
Author

leo9800 commented Sep 9, 2025

This is an interesting feature. Are you aware of any standardisation effort for that header?

seems there is not much such efforts (i.e. RFC drafts) from what i know.

it is an approach OwnCloud (predecessor of NextCloud) adopts to enable mtime presevation when uploading file via WebDAV as RFCs of WebDAV does not define a standard way to do so.

this feature is also implemented by rclone's rclone serve webdav WebDAV server command: https://github.com/rclone/rclone/blob/3f0e9f5fca8080f87094341f8ac5027091cc7601/cmd/serve/webdav/webdav.go#L339

given that this is a non-standard, i would implement it but keep it disabled by default to avoid any non-standard breaking change. users who prefer to use this feature should have it opted in manually with DAVHonorMtimeHeader On.

…mtime when `conf->honor_mtime_header == DAV_ENABLED_ON`,

                            check `set_mtime` callback is available before invoking, log debug-level messages
docs/log-message-tags: bumped with `docs/log-message-tags/update-log-msg-tags`

Signed-off-by: Leo <[email protected]>
…e_set` fails, emit error-level log message also

docs/log-message-tags: bumped with `docs/log-message-tags/update-log-msg-tags`

Signed-off-by: Leo <[email protected]>
@leo9800 leo9800 requested a review from notroj September 9, 2025 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants