MAN page from Other LWP.pm-5.48-2.i386.rpm
lib::HTTP::Response
Section: User Contributed Perl Documentation (3)
Updated: libwww-perl-5.48
Index NAME
HTTP::Response - Class encapsulating HTTP Responses
SYNOPSIS
require HTTP::Response;
DESCRIPTION
The
HTTP::Response class encapsulates HTTP style responses. Aresponse consists of a response line, some headers, and (potentiallyempty) content. Note that the LWP library also uses HTTP styleresponses for non-HTTP protocol schemes.
Instances of this class are usually created and returned by therequest() 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 thereforeinherits its methods. The inherited methods most often used are
header(),
push_header(),
remove_header(),
headers_as_string(), and
content().The header convenience methods are also available. Seethe
HTTP::Message manpage for details.
The following additional methods are available:
- $r = HTTP::Response->new($rc, [$msg, [$header, [$content]]])
- Constructs a new HTTP::Response object describing a response withresponse code $rc and optional message $msg. The message is ashort human readable single line string that explains the responsecode.
- $r->code([$code])
- $r->message([$message])
- $r->request([$request])
- $r->previous([$previousResponse])
- These methods provide public access to the object attributes. Thefirst two contain respectively the response code and the messageof the response.
The request attribute is a reference the request that caused thisresponse. It does not have to be the same request as passed to the$ua->request() method, because there might have been redirects andauthorization 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 orunauthorized.
- $r->status_line
- Returns the string ``<code> <message>''. If the message attributeis not set then the official name of <code> (see the HTTP::Status manpage)is substituted.
- $r->base
- Returns the base URL for this response. The return value will be areference to a URI object.
The base URL is obtained from one the following sources (in priorityorder):
- 1.
- Embedded in the document content, for instance <BASE HREF=''...">in HTML documents.
- 2.
- A ``Content-Base:'' or a ``Content-Location:'' header in the response.
For backwards compatability with older HTTP implementations we willalso look for the ``Base:'' header.
- 3.
- The URL used to request this response. This might not be the originalURL that was passed to $ua->request() method, because we might havereceived some redirect responses first.
When the LWP protocol modules produce the HTTP::Response object, thenany base URL embedded in the document (step 1) will already haveinitialized the ``Content-Base:'' header. This means that this methodonly performs the last 2 steps (the content is not always availableeither).
- $r->as_string
- Returns a textual representation of the response. Mainlyuseful for debugging purposes. It takes no arguments.
- $r->is_info
- $r->is_success
- $r->is_redirect
- $r->is_error
- These methods indicate if the response was informational, sucessful, aredirection, or an error.
- $r->error_as_HTML()
- Returns a string containing a complete HTML document indicating whaterror occurred. This method should only be called when $r->is_erroris TRUE.
- $r->current_age
- Calculates the ``current age'' of the response asspecified by <draft-ietf-http-v11-spec-07> section 13.2.3. Theage of a response is the time since it was sent by the origin server.The returned value is a number representing the age in seconds.
- $r->freshness_lifetime
- Calculates the ``freshness lifetime'' of the responseas specified by <draft-ietf-http-v11-spec-07> section 13.2.4. The``freshness lifetime'' is the length of time between the generation of aresponse and its expiration time. The returned value is a numberrepresenting the freshness lifetime in seconds.
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.
- $r->is_fresh
- Returns TRUE if the response is fresh, based on the values offreshness_lifetime() and current_age(). If the response is no longerfresh, then it has to be refetched or revalidated by the originserver.
- $r->fresh_until
- Returns the time when this entiy is no longer fresh.
COPYRIGHT
Copyright 1995-1997 Gisle Aas.
This library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- COPYRIGHT
This document was created byman2html,using the manual pages.