.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "HTTP::Response 3" .TH HTTP::Response 3 "2004-04-06" "perl v5.8.4" "User Contributed Perl Documentation" .SH "NAME" HTTP::Response \- HTTP style response message .SH "SYNOPSIS" .IX Header "SYNOPSIS" Response objects are returned by the \fIrequest()\fR method of the \f(CW\*(C`LWP::UserAgent\*(C'\fR: .PP .Vb 8 \& # ... \& $response = $ua->request($request) \& if ($response->is_success) { \& print $response->content; \& } \& else { \& print STDERR $response->status_line, "\en"; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \f(CW\*(C`HTTP::Response\*(C'\fR class encapsulates \s-1HTTP\s0 style responses. A response consists of a response line, some headers, and a content body. Note that the \s-1LWP\s0 library uses \s-1HTTP\s0 style responses even for non-HTTP protocol schemes. Instances of this class are usually created and returned by the \fIrequest()\fR method of an \f(CW\*(C`LWP::UserAgent\*(C'\fR object. .PP \&\f(CW\*(C`HTTP::Response\*(C'\fR is a subclass of \f(CW\*(C`HTTP::Message\*(C'\fR and therefore inherits its methods. The following additional methods are available: .ie n .IP "$r = HTTP::Response\->new( $code )" 4 .el .IP "$r = HTTP::Response\->new( \f(CW$code\fR )" 4 .IX Item "$r = HTTP::Response->new( $code )" .PD 0 .ie n .IP "$r = HTTP::Response\->new( $code\fR, \f(CW$msg )" 4 .el .IP "$r = HTTP::Response\->new( \f(CW$code\fR, \f(CW$msg\fR )" 4 .IX Item "$r = HTTP::Response->new( $code, $msg )" .ie n .IP "$r = HTTP::Response\->new( $code\fR, \f(CW$msg\fR, \f(CW$header )" 4 .el .IP "$r = HTTP::Response\->new( \f(CW$code\fR, \f(CW$msg\fR, \f(CW$header\fR )" 4 .IX Item "$r = HTTP::Response->new( $code, $msg, $header )" .ie n .IP "$r = HTTP::Response\->new( $code\fR, \f(CW$msg\fR, \f(CW$header\fR, \f(CW$content )" 4 .el .IP "$r = HTTP::Response\->new( \f(CW$code\fR, \f(CW$msg\fR, \f(CW$header\fR, \f(CW$content\fR )" 4 .IX Item "$r = HTTP::Response->new( $code, $msg, $header, $content )" .PD Constructs a new \f(CW\*(C`HTTP::Response\*(C'\fR object describing a response with response code \f(CW$code\fR and optional message \f(CW$msg\fR. The optional \f(CW$header\fR argument should be a reference to an \f(CW\*(C`HTTP::Headers\*(C'\fR object or a plain array reference of key/value pairs. The optional \f(CW$content\fR argument should be a string of bytes. The meaning these arguments are described below. .ie n .IP "$r = HTTP::Response\->parse( $str )" 4 .el .IP "$r = HTTP::Response\->parse( \f(CW$str\fR )" 4 .IX Item "$r = HTTP::Response->parse( $str )" This constructs a new response object by parsing the given string. .IP "$r\->code" 4 .IX Item "$r->code" .PD 0 .ie n .IP "$r\->code( $code )" 4 .el .IP "$r\->code( \f(CW$code\fR )" 4 .IX Item "$r->code( $code )" .PD This is used to get/set the code attribute. The code is a 3 digit number that encode the overall outcome of a \s-1HTTP\s0 response. The \&\f(CW\*(C`HTTP::Status\*(C'\fR module provide constants that provide mnemonic names for the code attribute. .IP "$r\->message" 4 .IX Item "$r->message" .PD 0 .ie n .IP "$r\->message( $message )" 4 .el .IP "$r\->message( \f(CW$message\fR )" 4 .IX Item "$r->message( $message )" .PD This is used to get/set the message attribute. The message is a short human readable single line string that explains the response code. .ie n .IP "$r\->header( $field )" 4 .el .IP "$r\->header( \f(CW$field\fR )" 4 .IX Item "$r->header( $field )" .PD 0 .ie n .IP "$r\->header( $field\fR => \f(CW$value )" 4 .el .IP "$r\->header( \f(CW$field\fR => \f(CW$value\fR )" 4 .IX Item "$r->header( $field => $value )" .PD This is used to get/set header values and it is inherited from \&\f(CW\*(C`HTTP::Headers\*(C'\fR via \f(CW\*(C`HTTP::Message\*(C'\fR. See HTTP::Headers for details and other similar methods that can be used to access the headers. .IP "$r\->content" 4 .IX Item "$r->content" .PD 0 .ie n .IP "$r\->content( $content )" 4 .el .IP "$r\->content( \f(CW$content\fR )" 4 .IX Item "$r->content( $content )" .PD This is used to get/set the raw content and it is inherited from the \&\f(CW\*(C`HTTP::Message\*(C'\fR base class. See HTTP::Message for details and other methods that can be used to access the content. .ie n .IP "$r\->decoded_content( %options )" 4 .el .IP "$r\->decoded_content( \f(CW%options\fR )" 4 .IX Item "$r->decoded_content( %options )" This will return the content after any \f(CW\*(C`Content\-Encoding\*(C'\fR and charsets has been decoded. See HTTP::Message for details. .IP "$r\->request" 4 .IX Item "$r->request" .PD 0 .ie n .IP "$r\->request( $request )" 4 .el .IP "$r\->request( \f(CW$request\fR )" 4 .IX Item "$r->request( $request )" .PD This is used to get/set the request attribute. The request attribute is a reference to the the request that caused this response. It does not have to be the same request passed to the \f(CW$ua\fR\->\fIrequest()\fR method, because there might have been redirects and authorization retries in between. .IP "$r\->previous" 4 .IX Item "$r->previous" .PD 0 .ie n .IP "$r\->previous( $response )" 4 .el .IP "$r\->previous( \f(CW$response\fR )" 4 .IX Item "$r->previous( $response )" .PD This is used to get/set the previous attribute. 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 value is \f(CW\*(C`undef\*(C'\fR if this is the first response in a chain. .IP "$r\->status_line" 4 .IX Item "$r->status_line" Returns the string " ". If the message attribute is not set then the official name of (see HTTP::Status) is substituted. .IP "$r\->base" 4 .IX Item "$r->base" Returns the base \s-1URI\s0 for this response. The return value will be a reference to a \s-1URI\s0 object. .Sp The base \s-1URI\s0 is obtained from one the following sources (in priority order): .RS 4 .IP "1." 4 Embedded in the document content, for instance <\s-1BASE\s0 HREF=\*(L"...\*(R"> in \s-1HTML\s0 documents. .IP "2." 4 A \*(L"Content\-Base:\*(R" or a \*(L"Content\-Location:\*(R" header in the response. .Sp For backwards compatibility with older \s-1HTTP\s0 implementations we will also look for the \*(L"Base:\*(R" header. .IP "3." 4 The \s-1URI\s0 used to request this response. This might not be the original \&\s-1URI\s0 that was passed to \f(CW$ua\fR\->\fIrequest()\fR method, because we might have received some redirect responses first. .RE .RS 4 .Sp If neither of these sources provide an absolute \s-1URI\s0, undef is returned. .Sp When the \s-1LWP\s0 protocol modules produce the HTTP::Response object, then any base \s-1URI\s0 embedded in the document (step 1) will already have initialized the \*(L"Content\-Base:\*(R" header. This means that this method only performs the last 2 steps (the content is not always available either). .RE .IP "$r\->as_string" 4 .IX Item "$r->as_string" .PD 0 .ie n .IP "$r\->as_string( $eol )" 4 .el .IP "$r\->as_string( \f(CW$eol\fR )" 4 .IX Item "$r->as_string( $eol )" .PD Returns a textual representation of the response. .IP "$r\->is_info" 4 .IX Item "$r->is_info" .PD 0 .IP "$r\->is_success" 4 .IX Item "$r->is_success" .IP "$r\->is_redirect" 4 .IX Item "$r->is_redirect" .IP "$r\->is_error" 4 .IX Item "$r->is_error" .PD These methods indicate if the response was informational, successful, a redirection, or an error. See HTTP::Status for the meaning of these. .IP "$r\->error_as_HTML" 4 .IX Item "$r->error_as_HTML" Returns a string containing a complete \s-1HTML\s0 document indicating what error occurred. This method should only be called when \f(CW$r\fR\->is_error is \s-1TRUE\s0. .IP "$r\->current_age" 4 .IX Item "$r->current_age" Calculates the \*(L"current age\*(R" of the response as specified by \s-1RFC\s0 2616 section 13.2.3. The age 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. .IP "$r\->freshness_lifetime" 4 .IX Item "$r->freshness_lifetime" Calculates the \*(L"freshness lifetime\*(R" of the response as specified by \&\s-1RFC\s0 2616 section 13.2.4. The \*(L"freshness lifetime\*(R" is the length of time between the generation of a response and its expiration time. The returned value is a number representing the freshness lifetime in seconds. .Sp If the response does not contain an \*(L"Expires\*(R" or a \*(L"Cache\-Control\*(R" header, then this function will apply some simple heuristic based on \&'Last\-Modified' to determine a suitable lifetime. .IP "$r\->is_fresh" 4 .IX Item "$r->is_fresh" Returns \s-1TRUE\s0 if the response is fresh, based on the values of \&\fIfreshness_lifetime()\fR and \fIcurrent_age()\fR. If the response is no longer fresh, then it has to be refetched or revalidated by the origin server. .IP "$r\->fresh_until" 4 .IX Item "$r->fresh_until" Returns the time when this entity is no longer fresh. .SH "SEE ALSO" .IX Header "SEE ALSO" HTTP::Headers, HTTP::Message, HTTP::Status, HTTP::Request .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 1995\-2004 Gisle Aas. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.