mholt / caddy-webdav

WebDAV handler module for Caddy
Apache License 2.0
198 stars 22 forks source link

PROPFIND of file that does not exist #11

Closed ghost closed 3 years ago

ghost commented 3 years ago

When receiving a PROPFIND request for a file that does not exist, the plugin is logging an internal handler error, instead of responding appropriately, which I imagine would be with a 404.

{
  "level": "error",
  "ts": 1595606346.000593,
  "logger": "http.handlers.webdav",
  "msg": "internal handler error",
  "error": "stat /var/www/.../image.png: no such file or directory",
  "request": {
    "method": "PROPFIND",
    "uri": "/webdav/.../image.png",
    "proto": "HTTP/1.1",
    "remote_addr": "...",
    "host": "example.com",
    "headers": {
      "Connection": [
        "close"
      ],
      "Content-Length": [
        "0"
      ],
      "Accept": [
        "text/plain"
      ],
      "Depth": [
        "0"
      ],
      "Authorization": [
        "Basic ..."
      ],
      "User-Agent": [
        "axios/0.18.0"
      ]
    },
    "tls": {
      "resumed": true,
      "version": 771,
      "ciphersuite": 52393,
      "proto": "",
      "proto_mutual": true,
      "server_name": "example.com"
    }
  }
}
mholt commented 3 years ago

Oh, yeah, hmm is there a way we can discern the error from the library and handle it appropriately?

wader commented 3 years ago

Did a quick test and it seems to return 404 for me or do i misunderstand? about the log message, the error passed to the Logger callback is a &os.PathError{Op:"stat", Path:"root/asdsad", Err:0x2}, maybe we can filter out based on that?

ghost commented 3 years ago

Did a little more digging. It looks like this is either an issue of the webdav library not conforming strictly to the spec, or my WebDAV client interpreting the spec too narrowly. Either way not a caddy plugin issue so closing.

Like @wader says it is returning a 404. Looks like the issue is either that it should be responding with an XML body along the lines of the below, or the client is wrongly expecting it to.

<?xml version="1.0" encoding="utf-8"?><d:error xmlns:d="DAV:"></d:error>
mholt commented 3 years ago

Thanks for looking into it more! If that's the case, then I agree the issue is either in the upstream lib or the downstream client. But I don't know the WebDAV protocol enough to know the answer without more research.

ghost commented 3 years ago

After trying to read the RFC tonight, I don't think it knows either. Who's idea was it to write a protocol spec in unstructured natural language? 😋