HTTP::DAV::Response(3pm) | User Contributed Perl Documentation | HTTP::DAV::Response(3pm) |
HTTP::DAV::Response - represents a WebDAV HTTP Response (ala HTTP::Response)
require HTTP::DAV::Response;
The HTTP::DAV::Response class encapsulates HTTP style responses. A response consists of a response line, some headers, and (potentially empty) content.
HTTP::DAV::Response is a subclass of "HTTP::Response" and therefore inherits its methods. (HTTP::Response in turn inherits it's methods from "HTTP::Message").
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.
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.
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, 424 and 507. Older versions of the LWP's C<HTTP::Status> class did not have these extra codes. These were added. - 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::Response can accurately parse these XML responses and emulate the normal of the C<HTTP::Response>.
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?).
There are only a handful of custom functions that HTTP::DAV::Response returns and those are to handle multistatus requests, "messages()" and "codes()".
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.
So, many DAV requests may return a multistatus ("207 multistatus") instead of, say, "200 OK" or "403 Forbidden".
The HTTP::DAV::Response object stores each "response" sent back in the multistatus. You access them by array number.
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.
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.
In this event, you may be interested in knowing what the individual messages were. To do this you would then use "messages".
foreach $num ( 0 ..
$response->response_count() ) {
print $response->message_bynum(); }
($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.
$code = $response->code_bynum(1);
See "response_bynum()"
$code = $response->message_bynum(1);
See "response_bynum()"
$code = $response->message_bynum(1);
See "response_bynum()"
$code = $response->message_description(1);
See "response_bynum()"
$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()".
2022-05-28 | perl v5.34.0 |