mholt / caddy-webdav

WebDAV handler module for Caddy
Apache License 2.0
222 stars 23 forks source link

HEAD requests should work also on folders #28

Closed mcieno closed 2 years ago

mcieno commented 2 years ago

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 commented 2 years ago

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

https://github.com/mholt/caddy-webdav/blob/f7b67f8ca1e655103bbe7a96577c88fe96f1dfb2/webdav.go#L105-L107

I can't remember why they are there, maybe from the previous webdav module in Caddy 1 that I ported over. :man_shrugging: Pull requests welcomed :smiley: