HTTP::Response - HTTP style response message |
HTTP::Response - HTTP style response message
version 6.18
Response objects are returned by the request()
method of the LWP::UserAgent
:
# ... $response = $ua->request($request); if ($response->is_success) { print $response->decoded_content; } else { print STDERR $response->status_line, "\n"; }
The HTTP::Response
class encapsulates HTTP style responses. A
response consists of a response line, some headers, and a content
body. Note that the LWP library uses HTTP style responses even for
non-HTTP protocol schemes. Instances of this class are usually
created and returned by the request()
method of an LWP::UserAgent
object.
HTTP::Response
is a subclass of HTTP::Message
and therefore
inherits its methods. The following additional methods are available:
HTTP::Response
object describing a response with
response code $code and optional message $msg. The optional $header
argument should be a reference to an HTTP::Headers
object or a
plain array reference of key/value pairs. The optional $content
argument should be a string of bytes. The meanings of these arguments are
described below.
HTTP::Status
module provide constants that provide mnemonic names
for the code attribute.
HTTP::Headers
via HTTP::Message
. See the HTTP::Headers manpage for
details and other similar methods that can be used to access the
headers.
HTTP::Message
base class. See the HTTP::Message manpage for details and
other methods that can be used to access the content.
Content-Encoding
and
charsets have been decoded. See the HTTP::Message manpage for details.
request()
method,
because there might have been redirects and authorization retries in
between.
undef
if this is the first response in a chain.
Note that the method $r->redirects is provided as a more convenient way to access the response chain.
The base URI is obtained from one the following sources (in priority order):
For backwards compatibility 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.
If none of these sources provide an absolute URI, undef is returned.
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. (See parse_head in the LWP::UserAgent manpage). This means that this method only performs the last 2 steps (the content is not always available either).
The filename is obtained from one the following sources (in priority order):
MIME::QuotedPrint
(for ``Q''
encoding), MIME::Base64
(for ``B'' encoding), and Encode
modules.
A ``Content-Location:'' header in the response.
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.
If a filename cannot be derived from any of these sources, undef is returned.
In scalar context return the number of redirect responses leading up to this one.
If the response does not contain an ``Expires'' or a ``Cache-Control'' header, then this function will apply some simple heuristic based on the ``Last-Modified'' header to determine a suitable lifetime. The following options might be passed to control the heuristics:
undef
when ``Expires'' or ``Cache-Control'' is lacking.
0.10
, the suggested typical setting of 10% in RFC 2616.
60
(1 minute).
86400
(24 hours).
3600
(1 hour) or ``h_min'' if greater.
freshness_lifetime()
and current_age(). If the response is no longer
fresh, then it has to be re-fetched or re-validated by the origin
server.
Options might be passed to control expiry heuristics, see the description of freshness_lifetime().
Options might be passed to control expiry heuristics, see the description of freshness_lifetime().
the HTTP::Headers manpage, the HTTP::Message manpage, the HTTP::Status manpage, the HTTP::Request manpage
Gisle Aas <gisle@activestate.com>
This software is copyright (c) 1994-2017 by Gisle Aas.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
HTTP::Response - HTTP style response message |