HTTP::D...Response(3)
๐ HTTP::DAV::Response ๐
Hey bestie ๐ welcome to the HTTP::D...Response(3) manual page from the User Contributed Perl Documentation โ yes, the name is literally truncated like that, and we're still slaying. This one is all about HTTP::DAV::Response, and it's giving very "subclass with main character energy" โจ
๐ NAME ๐
HTTP::DAV::Response โ represents a WebDAV HTTP Response (ala HTTP::Response). That's the name section, periodt. ๐
โจ SYNOPSIS โจ
require HTTP::DAV::Response;
Lowkey the whole synopsis. Iconic, honestly. ๐ฆ
๐ธ DESCRIPTION ๐ธ
The HTTP::DAV::Response class encapsulates HTTP style responses. A response consists of a response line, some headers, and (potentially empty) content. So far, so normal, bestie. ๐
HTTP::DAV::Response is a subclass of "HTTP::Response" and therefore inherits its methods. (HTTP::Response in turn inherits its methods from "HTTP::Message".) Yes, it's inheritance all the way down โ iykyk. ๐ง
Therefore, this class actually inherits a rich library of functions. You are more likely wanting to read the "HTTP::Response" class as opposed to this class. Literally, go read that one for most stuff โ I'm not kidding. ๐
Instances of this class are usually created by a "HTTP::DAV::Resource" object after it has performed some request (such as get, lock, delete, etc). You use the object to analyse the success or otherwise of the request. Vibe check on your DAV request, basically. โ
HTTP::DAV::Response was created to handle two extra functions that normal HTTP Responses don't require:
- WebDAV responses have 6 extra error codes:
102,207,422,423,424and507. Older versions of the LWP'sHTTP::Statusclass did not have these extra codes. These were added. Not me being grateful for extra status codes ๐ - WebDAV responses can actually contain more than one response (and often DO contain more than one) in the form of a
"Multistatus". These multistatus responses come in the form of an XML document.HTTP::DAV::Responsecan accurately parse these XML responses and emulate the normal of theHTTP::Response. Multistatus girlies rise up ๐
HTTP::DAV::Response transparently implements these extra features without the user having to be aware, so you really should be reading the "HTTP::Response" documentation for most of the things you want to do (have I already said that?). Yes, bestie, I have. But it's important. ๐ญ
There are only a handful of custom functions that HTTP::DAV::Response returns and those are to handle multistatus requests, messages() and codes(). Small API, big DAV energy. ๐
The six extra status codes that DAV servers can be returned in an HTTP Response are:
102 => "Processing. Server has accepted the request, but has not yet completed it",
207 => "Multistatus",
422 => "Unprocessable Entity. Bad client XML sent?",
423 => "Locked. The source or destination resource is locked",
424 => "Failed Dependency",
507 => "Insufficient Storage. The server is unable to store the request",
See "HTTP::Status" for the rest. Go check it, no cap. ๐ฆ
๐ HANDLING A MULTISTATUS ๐
So, many DAV requests may return a multistatus ("207 multistatus") instead of, say, "200 OK" or "403 Forbidden". Not the usual status code moment, but she's valid. ๐
The HTTP::DAV::Response object stores each "response" sent back in the multistatus. You access them by array number. Array number access โ very old-school, very reliable. ๐ฅ
The following code snippet shows what you will normally want to do:
... $response = $resource->lock();
if ( $response->is_multistatus() ) {
foreach $num ( 0 .. $response->response_count() ) {
($err_code,$mesg,$url,$desc) =
$response->response_bynum($num);
print "$mesg ($err_code) for $url\n";
}
}
Would produce something like this:
Failed Dependency (424) for /test/directory
Locked (423) for /test/directory/file3
This says that we couldn't lock /test/directory because file3 which exists inside is already locked by somebody else. Oop โ blocked by someone else's lock, literally. ๐
๐ METHODS ๐
is_multistatus
This function takes no arguments and returns a 1 or a 0. Boolean realness. โ
For example: if ($response->is_multistatus() ) { }
If the HTTP reply had "207 Multistatus" in the header then that indicates that there are multiple status messages in the XML content that was returned. Multistatus detected, bestie. ๐จ
In this event, you may be interested in knowing what the individual messages were. To do this you would then use "messages". Go off, messages. ๐ฌ
response_count
Takes no arguments and returns "the number of error responses -1" that we got. Why -1? Because usually you will want to use this like an array operator:
foreach $num ( 0 .. $response->response_count() ) {
print $response->message_bynum(); }
Yes, -1 is doing important math so your 0 .. loop behaves. Respect. ๐งฎ
response_bynum
Takes one argument, the response number that you're interested in. And returns an array of details:
($code,$message,$url,$description) = response_bynum(2);
where
$codeโ is the HTTP error code (e.g.403,423, etc).$messageโ is the associated message for that error code.$urlโ is the url that this error applies to (recall that there can be multiple responses within one response and they all relate to one URL)$descriptionโ is server's attempt at an english description of what happened.
Four lil values, one whole story about what went wrong. ๐
code_bynum
Takes one argument, the response number that you're interested in, and returns it's code. E.g:
$code = $response->code_bynum(1);
See response_bynum(). Same energy, one value at a time. โญ
message_bynum
Takes one argument, the response number that you're interested in, and returns it's message. E.g:
$code = $response->message_bynum(1);
See response_bynum(). Copying the original example exactly, bestie โ we don't fix, we preserve. ๐
url_bynum
Takes one argument, the response number that you're interested in, and returns it's url. E.g:
$code = $response->message_bynum(1);
See response_bynum(). Yes, the example literally says message_bynum here too โ original is original. ๐
description_bynum
Takes one argument, the response number that you're interested in, and returns it's description. E.g:
$code = $response->message_description(1);
See response_bynum(). Description unlocked. Server's English attempt, no cap. ๐
messages
Takes no arguments and returns all of the messages returned in a multistatus response. If called in a scalar context then all of the messages will be returned joined together by newlines. If called in an array context the messages will be returned as an array. Scalar vs array context โ pick your fighter. โ๏ธ
$messages = $response->messages(); e.g. $messages eq "Forbidden\nLocked";
@messages = $response->messages(); e.g. @messages eq ["Forbidden", "Locked"];
This routine is a variant on the standard "HTTP::Response" message(). Basically message() but multistatus-flavored. ๐ฆ
๐ Later, bestie! This page is from perl v5.42.0, dated 2024-10-17, and it's the HTTP::D...Response(3) manual page. Mwah! ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: perl-HTTP-DAV 0.500.0-160000.2.2 ยท Artistic-1.0 OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms