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

HEAD requests should work also on folders #28

Closed
mcieno opened this issue Mar 28, 2022 · 1 comment
Closed

HEAD requests should work also on folders #28

mcieno opened this issue Mar 28, 2022 · 1 comment

Comments

@mcieno
Copy link
Contributor

mcieno commented Mar 28, 2022

HEAD requests to folders return HTTP 405 Method Not Allowed.

I believe this is an issue because, according to RFC 4918§9.4, HEAD should be valid also on collections.

The current behaviour makes it impossible to use this extension with some WebDAV clients/libraries (e.g., java's Sardine).

How to reproduce

# Caddyfile
:8080
log
root * /var/www
route {
        webdav
}
# Content of the webroot
$ ls -lah /var/www
total 12K
drwxr-xr-x  3 root root 4.0K Jan 02 15:04 .
drwxr-xr-x 14 root root 4.0K Jan 02 15:04 ..
-rw-r--r--  1 root root   11 Jan 02 15:04 a-file
drwxr-xr-x  2 root root 4.0K Jan 02 15:04 a-folder

GET requests work for both file and folder:

$ curl -X GET http://localhost:8080/a-file
I'm a file

$ curl -X GET http://localhost:8080/a-folder
<?xml version="1.0" encoding="UTF-8"?><D:multistatus xmlns:D="DAV:"><D:response><D:href>/a-folder/</D:href><D:propstat><D:prop><D:getlastmodified>Mon, 02 Jan 2006 15:04:05 MST</D:getlastmodified><D:resourcetype><D:collection xmlns:D="DAV:"/></D:resourcetype><D:displayname>a-folder</D:displayname><D:supportedlock><D:lockentry xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>

HEAD requests to a-file work, but to a-folder fail:

$ curl --head http://localhost:8080/a-file
HTTP/1.1 200 OK
[...]

$ curl --head http://localhost:8080/a-folder
HTTP/1.1 405 Method Not Allowed
Server: Caddy
Date: Mon, 02 Jan 2006 15:04:05 MST

Note: This would close #19, where the workarounds proposed so far don't work.

@mholt
Copy link
Owner

mholt commented Mar 28, 2022

Huh; okay, yeah, the offending lines are probably these:

caddy-webdav/webdav.go

Lines 105 to 107 in f7b67f8

if r.Method == http.MethodHead {
w = emptyBodyResponseWriter{w}
}

I can't remember why they are there, maybe from the previous webdav module in Caddy 1 that I ported over. 🤷‍♂️ Pull requests welcomed 😃

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

No branches or pull requests

2 participants