This is still the header! Main site

WebDAV: the Awesome File Sharing Method No One Is Using

2021/01/29

... even though it's a web thing!

This is post no. 77 for Kev Quirk's #100DaysToOffload challenge. The point is to write many things, not to write good ones. Please adjust quality expectations accordingly :)

What is it?

It's a file access protocol, kinda like SMB or NFS. Except it's an extension of classic HTTP.

Basically, to fetch files, you're just doing basic HTTP GET. You can also upload files, using the PUT method... and you can get directory listings with PROPFIND, getting you beautiful answers like




<D:multistatus xmlns:D="DAV:">
   <D:response>
      <D:href>/pic_the_photos_version.jpg</D:href>
      <D:propstat>
         <D:prop>
            <D:getetag>"15ed7bb356eb260ca87246"</D:getetag>
            <D:supportedlock>
               <D:lockentry>
                  <D:lockscope>
                     <D:exclusive />
                  </D:lockscope>
                  <D:locktype>
                     <D:write />
                  </D:locktype>
               </D:lockentry>
            </D:supportedlock>
            <D:getcontentlength>11039302</D:getcontentlength>
            <D:getcontenttype>image/jpeg</D:getcontenttype>
            <D:resourcetype />
            <D:displayname>pic_the_photos_version.jpg</D:displayname>
            <D:getlastmodified>Sun, 26 Jan 2020 16:10:54 GMT</D:getlastmodified>
         </D:prop>
         <D:status>HTTP/1.1 200 OK</D:status>
      </D:propstat>
   </D:response>
   <D:response>
      <D:href>/pic_the_photos_version_noexif.jpg</D:href>
      <D:propstat>
         <D:prop>
            <D:supportedlock>
               <D:lockentry>
                  <D:lockscope>
                     <D:exclusive />
                  </D:lockscope>
                  <D:locktype>
                     <D:write />
                  </D:locktype>
               </D:lockentry>
            </D:supportedlock>
            <D:getcontentlength>3418837</D:getcontentlength>
            <D:getcontenttype>image/jpeg</D:getcontenttype>
            <D:getetag>"15ed7bbf5db6ebc3342ad5"</D:getetag>
            <D:resourcetype />
            <D:displayname>pic_the_photos_version_noexif.jpg</D:displayname>
            <D:getlastmodified>Sun, 26 Jan 2020 16:11:46 GMT</D:getlastmodified>
         </D:prop>
         <D:status>HTTP/1.1 200 OK</D:status>
      </D:propstat>
   </D:response>

          

(... ever heard of the HTTP result code 207 Multi-Status? Well, the above is an example for that.)

You might have heard about CardDAV and CalDAV; these are protocols for syncing contacts and calendars. WebDAV is somewhere underneath these, too (except with more fancy metadata).

Why is it cool?

... well, apart from producing impressively verbose directory listings? Like... don't you need some arcane Apache modules to set up...

simon@some-hostname ~/tmp [SIGINT]> rclone serve webdav --addr 0.0.0.0:8082 .
2022/02/07 21:23:50 NOTICE: Config file "/home/simon/.config/rclone/rclone.conf" not found - using defaults
2022/02/07 21:23:50 NOTICE: Local file system at /home/simon/tmp: WebDav Server started on http://[::]:8082/
          

... well okay, that wasn't that hard. (rclone, by the way, exists; this is the first time I'm using it, but I've heard people claim that it's magic.)

(And yes, of course, you can set up Apache to be a WebDAV server, too.)

But sure, we are now serving some files over a protocol that you can't access from any operating sys...

webdav directory mounted from windows

... which you can't even mount as a file system on...

simon@some-hostname ~> sudo mount -t davfs http://localhost:8082/ tmp2
Please enter the username to authenticate with server
http://localhost:8082/ or hit enter for none.
  Username:
Please enter the password to authenticate user  with server
http://localhost:8082/ or hit enter for none.
  Password:
simon@some-hostname ~> ls tmp2
lost+found/  pic_the_photos_version.jpg  pic_the_photos_version_noexif.jpg
          

Well, okay, sure. Maybe it's about... as cool as SSHFS or SMB or one of those. Except it's a bit easier to set up a server for it. A bit.

Was that it?

As in... you can just mount a file system, across the entire Internet, possibly over HTTPS, supported by major operating systems? How is this not being used all the time?

(I actually thought that such a thing didn't even exist, and left it out of my earlier article completely. Little did I know.)

But... yes, it exists. It's just running over standard HTTP, which means that you can:

But that's still just scratching the surface.

You can write a WebDAV server.

No, I haven't actually tried doing this.

Yet.

However... if you think about it: it's just plain HTTP (almost). Especially if you don't insist on writeability, the only thing you need to add is responses to PROPFIND (... the one requesting directory listings). Any programming language / web framework that doesn't strictly insist on all HTTP requests being either "GET" or "POST" can do this.

And then you mount this and you have a file system.

You can mount your web app as a file system.

The closest you can get to this is with FUSE file systems in Linux; good luck to you for dealing with language bindings, inodes and all the fields of stat requests. (Also, if you want to provide the same functionality for Windows... you better start over.) Instead, with WebDAV, you get instant, secure, network-capable magic that fits neatly behind your proxy.

This should have been a thing.

Imagine if you could mount your Facebook photo gallery on your desktop computer. (... well, Facebook obviously doesn't want you to do this.)

Imagine every "cloud" service giving you access in the form of actual files that you can download / locally edit / store / back up. Or a cloud editor thing having you log in to your actual storage provider via OAuth and letting you edit your files. Interoperability!

(... of course, they don't want this one, either.)

On the other hand... even if it didn't happen yet... you can write some of these things. And then they will exist!

... comments welcome, either in email or on the (eventual) Mastodon post on Fosstodon.