|
|
HTTP::Response - Class encapsulating HTTP Responses
require HTTP::Response;
The HTTP::Response
class encapsulates HTTP style responses. A
response consists of a response line, some headers, and (potentially
empty) content. Note that the LWP library also uses HTTP style
responses for non-HTTP protocol schemes.
Instances of this class are usually created and returned by the
request()
method of an LWP::UserAgent
object:
#... $response = $ua->request($request) if ($response->is_success) { print $response->content; } else { print $response->error_as_HTML; }
HTTP::Response
is a subclass of HTTP::Message
and therefore
inherits its methods. The inherited methods most often used are header(),
push_header(), remove_header(), and content().
The header convenience methods are also available. See
the HTTP::Message manpage for details.
The following additional methods are available:
HTTP::Response
object describing a response with
response code $rc
and optional message $msg
. The message is a
short human readable single line string that explains the response
code.
code([$code])
message([$message])
request([$request])
previous([$previousResponse])
The request attribute is a reference the request that caused this
response. It does not have to be the same request as passed to the
$ua->request()
method, because there might have been redirects and
authorization retries in between.
The previous attribute is used to link together chains of responses. You get chains of responses if the first response is redirect or unauthorized.
The base URI is obtained from one the following sources (in priority order):
For backwards compatability with older HTTP implementations we will also look for the ``Base:'' header.
The URI used to request this response. This might not be the original URI that was passed to $ua->request()
method, because we might have
received some redirect responses first.
When the LWP protocol modules produce the HTTP::Response object, then any base URI embedded in the document (step 1) will already have initialized the ``Content-Base:'' header. This means that this method only performs the last 2 steps (the content is not always available either).
error_as_HTML()
If the response does not contain an ``Expires'' or a ``Cache-Control'' header, then this function will apply some simple heuristic based on 'Last-Modified' to determine a suitable lifetime.
freshness_lifetime()
and current_age(). If the response is no longer
fresh, then it has to be refetched or revalidated by the origin
server.
Copyright 1995-2001 Gisle Aas.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.