skleblan has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to learn how to use WebDAV with Perl. My main use-case is simply downloading several files and folders (I think the term is collections in DAV??). I'm using App::DAVThis to stand up a simple test server, and I'm trying to learn how to use HTTP::DAV but I'm having some issues getting it to work. I was hoping that after I got it working with dav_this (the name of the executable script), then I can move on to a production server that supports https.

I keep getting errors regarding Bad Requests. Does anyone know if I'm using the module correctly? The frustrating thing is that I can use cadaver to connect to the temp server and it works just fine.

Test Code

#!/usr/bin/env perl use strict; use warnings; use utf8; use HTTP::DAV; my $url = "http://localhost:4242/"; my $dav = HTTP::DAV->new; $dav->open(-url=>$url) or die $dav->message; $dav->get(-url=>"/", -to=>".");

Error message

Server response: Could not access http://localhost:4242/: Bad Request +at davtest.pl line 14.

Replies are listed 'Best First'.
Re: Problems learning WebDAV with dav_this and HTTP::DAV
by haukex (Archbishop) on Oct 28, 2019 at 21:41 UTC

    The trace on this is:

    The difference between e.g. Nautilus and HTTP::DAV is that the former sends a <D:propfind xmlns:D="DAV:"><D:prop>... request, while the latter sends a <D:propfind xmlns:D="DAV:"><D:allprop/>... request, which hits the above branch of code. There, the propfind method attempts to use the HTTP Basic Auth user credentials, which it doesn't have because AFAICT it never requests them from the client (Update: and at the moment I don't see a way to force the client to send the auth, although I may be missing something).

    Unfortunately, that's where my analysis ends for now - I don't know much about WebDAV and I'm not sure which module is at fault here, although I suspect it's Net::DAV::Server not handling this type of request, because the HTTP::DAV client code seems to work fine for me on two different servers. So you might just want to use a different server for testing, and perhaps file a bug for Net::DAV::Server (although that module hasn't been updated since 2013).

    I like to sometimes use lighttpd for quick & dirty test servers. On Ubuntu, sudo apt-get install --no-install-recommends lighttpd lighttpd-mod-webdav, sudo systemctl stop lighttpd, and sudo systemctl disable lighttpd (assuming you don't want it running all the time), then create a file /tmp/lhttpd.conf with the following contents (module docs):

    server.document-root = "/tmp/foo/" server.port = 4242 server.bind = "127.0.0.1" server.modules += ( "mod_webdav" ) $HTTP["url"] =~ "^/dav($|/)" { webdav.activate = "enable" #webdav.is-readonly = "disable" # (default) webdav.sqlite-db-name = "/tmp/foo_webdav.db" }

    Then run mkdir -p /tmp/foo/dav and lighttpd -Df /tmp/lhttpd.conf, and you can then access the server using HTTP::DAV at http://localhost:4242/dav/.

    There are lots of other modules available, see the files (including the README) that get installed at /etc/lighttpd/conf-available, it includes SSL, authentication, CGI, and FastCGI.

      haukex, thank you for the detailed response. I’m a little disappointed that App::DAVThis didn’t work out. It seemed like such an easy and convenient way to bring up a test server. I tried out lighttpd and I was able to get my test script working. I’ll continue to use it in my experimentation. Thanks for that suggestion.