Skip to content

WebDAV: Add depth header to service discovery request for Hetzner compatibility#4608

Merged
lastzero merged 1 commit into
photoprism:developfrom
esteve:propfind-depth-1
Mar 27, 2025
Merged

WebDAV: Add depth header to service discovery request for Hetzner compatibility#4608
lastzero merged 1 commit into
photoprism:developfrom
esteve:propfind-depth-1

Conversation

@esteve

@esteve esteve commented Nov 3, 2024

Copy link
Copy Markdown
Contributor

I noticed that I couldn't connect to my Hetzner storage box via webdav, as it does not allow PROPFIND requests without Depth set as 0 or 1. When a request is created via NewRequest it doesn't have a Depth field, which Hetzner interprets as infinity:

$ curl -X PROPFIND https://XXXX:XXXXX@XXXXXXXXX/webdav/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>PROPFIND requests with a Depth of "infinity" are not allowed for /webdav/.</p>
</body></html>

I believe this is the same issue as #4074 #3541

I've tested the change locally and it works. However photoprism still uses PROPFIND with Depth = infinity somehwere else, I'd suspect it's because of

subDirs, err := client.Directories(a.SyncPath, true, webdav.MaxRequestDuration)
, but this is the first Go code I've ever written and I'm not familiar with the http and webdav packages.

Signed-off-by: Esteve Fernandez <esteve@apache.org>
@CLAassistant

CLAassistant commented Nov 3, 2024

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@esteve esteve marked this pull request as ready for review November 3, 2024 16:07
@gOOvER

gOOvER commented Nov 10, 2024

Copy link
Copy Markdown

i have the same problem with hetzner and i would be happy, when this could be merged asap

@lastzero

Copy link
Copy Markdown
Member

Thank you so much for submitting this PR! My apologies for not getting back to you sooner. I've been helping our team with the frontend update, which is now complete, so I can finally check the open PRs and merge them :)

@lastzero lastzero changed the title Fix: use Depth = 1 for PROPFIND, fixes connecting to Hetzner WebDAV: Add depth header to service discovery request for Hetzner compatibility Mar 27, 2025
@lastzero lastzero added enhancement sharing Sharing with users, anonymously via links or publicly labels Mar 27, 2025
@lastzero lastzero moved this to Development 🐝 in Roadmap πŸš€βœ¨ Mar 27, 2025
@lastzero lastzero merged commit a36e8b1 into photoprism:develop Mar 27, 2025
lastzero added a commit that referenced this pull request Mar 27, 2025


Signed-off-by: Michael Mayer <michael@photoprism.app>
@lastzero

Copy link
Copy Markdown
Member

@esteve The above changes allow you to set custom request headers in the service type configuration, rather than adding a Depth header to all requests.

However, you are right that this may not be enough for you to use the service, since our WebDAV client currently only makes a single, recursive request to get a list of files and folders on the remote server:

This could be solved by implementing a fallback that makes multiple requests to get the contents of the remote folders for synchronization; for example, you could implement the Directories() function differently and use it when certain errors are detected in line 148 (see the source code of earlier releases for inspiration):

// Directories returns all subdirectories in a path as string slice.
func (c *Client) Directories(dir string, recursive bool, timeout time.Duration) (result fs.FileInfos, err error) {
dir = trimPath(dir)
found, err := c.readDirWithTimeout(dir, recursive, timeout)
if err != nil {
return result, err
}
result = make(fs.FileInfos, 0, len(found))
for _, f := range found {
if !f.IsDir || f.Path == "" || strings.HasPrefix(f.Path, ".") {
continue
}
info := fs.WebFileInfo(f, c.endpoint.Path)
result = append(result, info)
}
return result, err
}

@lastzero lastzero added the merged Changes are merged, but may require further testing label Mar 27, 2025
@lastzero lastzero moved this from Development 🐝 to Preview 🐳 in Roadmap πŸš€βœ¨ Mar 27, 2025
@lastzero lastzero added the please-test Ready for manual testing & feedback label Mar 27, 2025
@lastzero

Copy link
Copy Markdown
Member

@esteve esteve deleted the propfind-depth-1 branch March 27, 2025 08:33
@esteve

esteve commented Mar 27, 2025

Copy link
Copy Markdown
Contributor Author

@lastzero thank you for merging this PR πŸ™‚

@graciousgrey graciousgrey added tested Changes have been tested successfully and removed please-test Ready for manual testing & feedback labels Apr 24, 2025
@graciousgrey graciousgrey moved this from Preview 🐳 to Release 🌈 in Roadmap πŸš€βœ¨ Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged Changes are merged, but may require further testing sharing Sharing with users, anonymously via links or publicly tested Changes have been tested successfully

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants