terreng / simple-web-server

Create a local web server in just a few clicks with an easy to use interface. Built with Electron.
https://simplewebserver.org
MIT License
210 stars 58 forks source link

WebDAV #130

Open stokito opened 1 year ago

stokito commented 1 year ago

The server already has a directory listing. But with just few small changes it may also support WebDAV file transfer protocol. This will allow to mount a folder or use many other programs to work with files e.g. music players, backup/sync tools. By implementing also LOCK, PUT, DELETE, MKCOL methods the folder can be also be edited but this increases complexity.

With this feature users will easier share files and can have a small personal cloud.

The original 200 OK server also had the feature request https://github.com/kzahel/web-server-chrome/issues/143

terreng commented 1 year ago

@ethanaobrien Want to look into this? How hard would it be to add?

stokito commented 1 year ago

A simplest read only would be:

  1. Handle OPTIONS and return two headers DAV: 1,2,3 and Allow: PROPFIND, GET
  2. Handle PROPFIND and return directory listing but in XML form like:
<?xml version="1.0" encoding="UTF-8"?>
<D:multistatus xmlns:D="DAV:">
    <D:response>
        <D:href>/dav/Some%20Folder/</D:href>
        <D:propstat>
            <D:prop>
                <D:resourcetype>
                    <D:collection/>
                </D:resourcetype>
                <D:getlastmodified>Wed, 08 Mar 2023 12:45:54 GMT</D:getlastmodified>
            </D:prop>
            <D:status>HTTP/1.1 200 OK</D:status>
        </D:propstat>
    </D:response>

    <D:response>
        <D:href>/dav/README.txt</D:href>
        <D:propstat>
            <D:prop>
                <D:resourcetype></D:resourcetype>
                <D:getcontentlength>64</D:getcontentlength>
                <D:getcontenttype>text/plain</D:getcontenttype>
                <D:getetag>"174a620a4078606440"</D:getetag>
                <D:getlastmodified>Wed, 08 Mar 2023 12:45:54 GMT</D:getlastmodified>
            </D:prop>
            <D:status>HTTP/1.1 200 OK</D:status>
        </D:propstat>
    </D:response>
</D:multistatus>

So here we have a folder Some Folder but it's href e.g. path of URL is /dav/Some%20Folder/ and space was URL escaped to %20. We know that this is a folder because it has <D:resourcetype> <D:collection/> </D:resourcetype>.

Next we have a README.txt file with href /dav/README.txt. It has <D:resourcetype></D:resourcetype> e.g. empty.