Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve WebDAV compatibility #681

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal abstract class WebDavStorage(
callback = callback,
)
} catch (e: HttpException) {
if (e.code == 400) {
if (e.isUnsupportedPropfind()) {
Log.i(TAG, "Got ${e.response}, trying two depth=1 PROPFINDs...")
propfindFakeTwo(callback)
} else {
Expand All @@ -169,6 +169,18 @@ internal abstract class WebDavStorage(
}
}

protected fun HttpException.isUnsupportedPropfind(): Boolean {
// nginx returns 400 for depth=2
if (code == 400) {
return true
}
// lighttpd returns 403 with <DAV:propfind-finite-depth/> error as if we used infinity

Choose a reason for hiding this comment

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

FYI: lighttpd does support Depth: infinity but the feature is disabled by default since it can be slow on very large directory trees on very slow disks.

Since lighttpd 1.4.56 (released Nov 2020), you can add to lighttpd.conf:
webdav.opts += ("propfind-depth-infinity" => "enable")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice to know, but does it also support off-spec stuff like Depth: 2 like SabreDAV?

@t-m-w may be worth re-testing lighttpd with that option enabled.

Choose a reason for hiding this comment

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

but does it also support off-spec stuff like Depth: 2 like SabreDAV?

No, lighttpd mod_webdav does not support "off-spec" that I have not seen before. Do you have a reference to SabreDAV doc describing the behavior? (I can guess, but I'd rather not.)

From a (very, very, very quick) grep of https://github.com/sabre-io/dav, the code comments about Depth: 2 for use with CalDAV. The CalDAV spec is not currently implemented by lighttpd mod_webdav.

However, you can use lighttpd mod_webdav to serve file-backed collections, and you can have lighttpd route CalDAV url-paths back to nextcloud or owncloud sabredav-based backends.

if (code == 403 && responseBody?.contains("propfind-finite-depth") == true) {
return true
}
return false
}

protected suspend fun DavCollection.createFolder(xmlBody: String? = null): okhttp3.Response {
return try {
suspendCoroutine { cont ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ internal class WebDavStoragePlugin(
}
}
} catch (e: HttpException) {
if (e.code == 400) getBackupTokenWithDepthOne(davCollection, tokens)
if (e.isUnsupportedPropfind()) getBackupTokenWithDepthOne(davCollection, tokens)
else throw e
}
val tokenIterator = tokens.iterator()
Expand Down