How to implement https support for Perl's HTTP::DAV

Viewed 129

I am trying to access a remote server via the WebDav protocol, and more specifically Perl's HTTP::DAV module.

According to its documentation the coupling to a remote directory takes place in the following manner:

use HTTP::DAV;
 
$d = HTTP::DAV->new();
$url = "http://host.org:8080/dav/";
 
$d->credentials(
   -user  => "pcollins",
   -pass  => "mypass", 
   -url   => $url,
   -realm => "DAV Realm"
);
 
$d->open( -url => $url )
   or die("Couldn't open $url: " .$d->message . "\n");

I created a local webdav directory and can access it flawlessly over the http protocol.

According to HTTP::DAV's documentation, there should be and https support as well using the Crypt::SSLeay module.

The Crypt::SSLeay's documention offers us the following synopsys using inside the LWP::UserAgent module, thus providing for us web resource access over the https protocol:

use Net::SSL;
use LWP::UserAgent;
 
my $ua  = LWP::UserAgent->new(
    ssl_opts => { verify_hostname => 0 },
);
 
my $response = $ua->get('https://www.example.com/');
print $response->content, "\n";

My question is: How can I combine the HTTP::DAV and Crypt::SSLeay modules in order to have web resource access over the WebDav and https protocols?

Something like the following:

use HTTP::DAV; 

$d = HTTP::DAV->new();

$url = "https://host.org:8080/dav/";

#...
1 Answers

This is untested, but from skimming the documentation, this should work:

$d->get_user_agent->ssl_opts( verify_hostname => 0 );

The documentation for HTTP::DAV says:

get_user_agent

Returns the clients' working HTTP::DAV::UserAgent object.

You may want to interact with the HTTP::DAV::UserAgent object to modify request headers or provide advanced authentication procedures.

HTTP::DAV::UserAgent isn't documented, but its source code shows it's a subclass of LWP::UserAgent. The documentation for LWP::UserAgent mentions the ssl_opts method for setting SSL options for the user agent object.

Related