1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
4 .\" ========================================================================
5 .de Sh \" Subsection heading
13 .de Sp \" Vertical space (when we can't use .PP)
17 .de Vb \" Begin verbatim text
22 .de Ve \" End verbatim text
26 .\" Set up some character translations and predefined strings. \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote. | will give a
29 .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
37 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD. Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
57 . tm Index:\\$1\t\\n%\t"\\$2"
63 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear. Run. Save yourself. No user-serviceable parts.
70 . \" fudge factors for nroff and troff
79 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
85 . \" simple accents for nroff and troff
95 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
102 . \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 . \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 . \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
129 .\" ========================================================================
131 .IX Title "HTTP::Response 3"
132 .TH HTTP::Response 3 "2009-06-15" "perl v5.8.7" "User Contributed Perl Documentation"
134 HTTP::Response \- HTTP style response message
136 .IX Header "SYNOPSIS"
137 Response objects are returned by the \fIrequest()\fR method of the \f(CW\*(C`LWP::UserAgent\*(C'\fR:
141 \& $response = $ua\->request($request)
142 \& if ($response\->is_success) {
143 \& print $response\->content;
146 \& print STDERR $response\->status_line, "\en";
150 .IX Header "DESCRIPTION"
151 The \f(CW\*(C`HTTP::Response\*(C'\fR class encapsulates \s-1HTTP\s0 style responses. A
152 response consists of a response line, some headers, and a content
153 body. Note that the \s-1LWP\s0 library uses \s-1HTTP\s0 style responses even for
154 non-HTTP protocol schemes. Instances of this class are usually
155 created and returned by the \fIrequest()\fR method of an \f(CW\*(C`LWP::UserAgent\*(C'\fR
158 \&\f(CW\*(C`HTTP::Response\*(C'\fR is a subclass of \f(CW\*(C`HTTP::Message\*(C'\fR and therefore
159 inherits its methods. The following additional methods are available:
160 .ie n .IP "$r = HTTP::Response\->new( $code )" 4
161 .el .IP "$r = HTTP::Response\->new( \f(CW$code\fR )" 4
162 .IX Item "$r = HTTP::Response->new( $code )"
164 .ie n .IP "$r = HTTP::Response\->new( $code\fR, \f(CW$msg )" 4
165 .el .IP "$r = HTTP::Response\->new( \f(CW$code\fR, \f(CW$msg\fR )" 4
166 .IX Item "$r = HTTP::Response->new( $code, $msg )"
167 .ie n .IP "$r = HTTP::Response\->new( $code\fR, \f(CW$msg\fR, \f(CW$header )" 4
168 .el .IP "$r = HTTP::Response\->new( \f(CW$code\fR, \f(CW$msg\fR, \f(CW$header\fR )" 4
169 .IX Item "$r = HTTP::Response->new( $code, $msg, $header )"
170 .ie n .IP "$r = HTTP::Response\->new( $code\fR, \f(CW$msg\fR, \f(CW$header\fR, \f(CW$content )" 4
171 .el .IP "$r = HTTP::Response\->new( \f(CW$code\fR, \f(CW$msg\fR, \f(CW$header\fR, \f(CW$content\fR )" 4
172 .IX Item "$r = HTTP::Response->new( $code, $msg, $header, $content )"
174 Constructs a new \f(CW\*(C`HTTP::Response\*(C'\fR object describing a response with
175 response code \f(CW$code\fR and optional message \f(CW$msg\fR. The optional \f(CW$header\fR
176 argument should be a reference to an \f(CW\*(C`HTTP::Headers\*(C'\fR object or a
177 plain array reference of key/value pairs. The optional \f(CW$content\fR
178 argument should be a string of bytes. The meaning these arguments are
180 .ie n .IP "$r = HTTP::Response\->parse( $str )" 4
181 .el .IP "$r = HTTP::Response\->parse( \f(CW$str\fR )" 4
182 .IX Item "$r = HTTP::Response->parse( $str )"
183 This constructs a new response object by parsing the given string.
187 .ie n .IP "$r\->code( $code )" 4
188 .el .IP "$r\->code( \f(CW$code\fR )" 4
189 .IX Item "$r->code( $code )"
191 This is used to get/set the code attribute. The code is a 3 digit
192 number that encode the overall outcome of a \s-1HTTP\s0 response. The
193 \&\f(CW\*(C`HTTP::Status\*(C'\fR module provide constants that provide mnemonic names
194 for the code attribute.
196 .IX Item "$r->message"
198 .ie n .IP "$r\->message( $message )" 4
199 .el .IP "$r\->message( \f(CW$message\fR )" 4
200 .IX Item "$r->message( $message )"
202 This is used to get/set the message attribute. The message is a short
203 human readable single line string that explains the response code.
204 .ie n .IP "$r\->header( $field )" 4
205 .el .IP "$r\->header( \f(CW$field\fR )" 4
206 .IX Item "$r->header( $field )"
208 .ie n .IP "$r\->header( $field\fR => \f(CW$value )" 4
209 .el .IP "$r\->header( \f(CW$field\fR => \f(CW$value\fR )" 4
210 .IX Item "$r->header( $field => $value )"
212 This is used to get/set header values and it is inherited from
213 \&\f(CW\*(C`HTTP::Headers\*(C'\fR via \f(CW\*(C`HTTP::Message\*(C'\fR. See HTTP::Headers for
214 details and other similar methods that can be used to access the
217 .IX Item "$r->content"
219 .ie n .IP "$r\->content( $bytes )" 4
220 .el .IP "$r\->content( \f(CW$bytes\fR )" 4
221 .IX Item "$r->content( $bytes )"
223 This is used to get/set the raw content and it is inherited from the
224 \&\f(CW\*(C`HTTP::Message\*(C'\fR base class. See HTTP::Message for details and
225 other methods that can be used to access the content.
226 .ie n .IP "$r\->decoded_content( %options )" 4
227 .el .IP "$r\->decoded_content( \f(CW%options\fR )" 4
228 .IX Item "$r->decoded_content( %options )"
229 This will return the content after any \f(CW\*(C`Content\-Encoding\*(C'\fR and
230 charsets have been decoded. See HTTP::Message for details.
232 .IX Item "$r->request"
234 .ie n .IP "$r\->request( $request )" 4
235 .el .IP "$r\->request( \f(CW$request\fR )" 4
236 .IX Item "$r->request( $request )"
238 This is used to get/set the request attribute. The request attribute
239 is a reference to the the request that caused this response. It does
240 not have to be the same request passed to the \f(CW$ua\fR\->\fIrequest()\fR method,
241 because there might have been redirects and authorization retries in
243 .IP "$r\->previous" 4
244 .IX Item "$r->previous"
246 .ie n .IP "$r\->previous( $response )" 4
247 .el .IP "$r\->previous( \f(CW$response\fR )" 4
248 .IX Item "$r->previous( $response )"
250 This is used to get/set the previous attribute. The previous
251 attribute is used to link together chains of responses. You get
252 chains of responses if the first response is redirect or unauthorized.
253 The value is \f(CW\*(C`undef\*(C'\fR if this is the first response in a chain.
255 Note that the method \f(CW$r\fR\->redirects is provided as a more convenient
256 way to access the response chain.
257 .IP "$r\->status_line" 4
258 .IX Item "$r->status_line"
259 Returns the string "<code> <message>". If the message attribute
260 is not set then the official name of <code> (see HTTP::Status)
264 Returns the base \s-1URI\s0 for this response. The return value will be a
265 reference to a \s-1URI\s0 object.
267 The base \s-1URI\s0 is obtained from one the following sources (in priority
271 Embedded in the document content, for instance <\s-1BASE\s0 HREF=\*(L"...\*(R">
272 in \s-1HTML\s0 documents.
274 A \*(L"Content\-Base:\*(R" or a \*(L"Content\-Location:\*(R" header in the response.
276 For backwards compatibility with older \s-1HTTP\s0 implementations we will
277 also look for the \*(L"Base:\*(R" header.
279 The \s-1URI\s0 used to request this response. This might not be the original
280 \&\s-1URI\s0 that was passed to \f(CW$ua\fR\->\fIrequest()\fR method, because we might have
281 received some redirect responses first.
285 If none of these sources provide an absolute \s-1URI\s0, undef is returned.
287 When the \s-1LWP\s0 protocol modules produce the HTTP::Response object, then
288 any base \s-1URI\s0 embedded in the document (step 1) will already have
289 initialized the \*(L"Content\-Base:\*(R" header. This means that this method
290 only performs the last 2 steps (the content is not always available
293 .IP "$r\->filename" 4
294 .IX Item "$r->filename"
295 Returns a filename for this response. Note that doing sanity checks
296 on the returned filename (eg. removing characters that cannot be used
297 on the target filesystem where the filename would be used, and
298 laundering it for security purposes) are the caller's responsibility;
299 the only related thing done by this method is that it makes a simple
300 attempt to return a plain filename with no preceding path segments.
302 The filename is obtained from one the following sources (in priority
306 A \*(L"Content\-Disposition:\*(R" header in the response. Proper decoding of
307 \&\s-1RFC\s0 2047 encoded filenames requires the \f(CW\*(C`MIME::QuotedPrint\*(C'\fR (for \*(L"Q\*(R"
308 encoding), \f(CW\*(C`MIME::Base64\*(C'\fR (for \*(L"B\*(R" encoding), and \f(CW\*(C`Encode\*(C'\fR modules.
310 A \*(L"Content\-Location:\*(R" header in the response.
312 The \s-1URI\s0 used to request this response. This might not be the original
313 \&\s-1URI\s0 that was passed to \f(CW$ua\fR\->\fIrequest()\fR method, because we might have
314 received some redirect responses first.
318 If a filename cannot be derived from any of these sources, undef is
321 .IP "$r\->as_string" 4
322 .IX Item "$r->as_string"
324 .ie n .IP "$r\->as_string( $eol )" 4
325 .el .IP "$r\->as_string( \f(CW$eol\fR )" 4
326 .IX Item "$r->as_string( $eol )"
328 Returns a textual representation of the response.
330 .IX Item "$r->is_info"
332 .IP "$r\->is_success" 4
333 .IX Item "$r->is_success"
334 .IP "$r\->is_redirect" 4
335 .IX Item "$r->is_redirect"
336 .IP "$r\->is_error" 4
337 .IX Item "$r->is_error"
339 These methods indicate if the response was informational, successful, a
340 redirection, or an error. See HTTP::Status for the meaning of these.
341 .IP "$r\->error_as_HTML" 4
342 .IX Item "$r->error_as_HTML"
343 Returns a string containing a complete \s-1HTML\s0 document indicating what
344 error occurred. This method should only be called when \f(CW$r\fR\->is_error
346 .IP "$r\->redirects" 4
347 .IX Item "$r->redirects"
348 Returns the list of redirect responses that lead up to this response
349 by following the \f(CW$r\fR\->previous chain. The list order is oldest first.
351 In scalar context return the number of redirect responses leading up
353 .IP "$r\->current_age" 4
354 .IX Item "$r->current_age"
355 Calculates the \*(L"current age\*(R" of the response as specified by \s-1RFC\s0 2616
356 section 13.2.3. The age of a response is the time since it was sent
357 by the origin server. The returned value is a number representing the
359 .ie n .IP "$r\->freshness_lifetime( %opt )" 4
360 .el .IP "$r\->freshness_lifetime( \f(CW%opt\fR )" 4
361 .IX Item "$r->freshness_lifetime( %opt )"
362 Calculates the \*(L"freshness lifetime\*(R" of the response as specified by
363 \&\s-1RFC\s0 2616 section 13.2.4. The \*(L"freshness lifetime\*(R" is the length of
364 time between the generation of a response and its expiration time.
365 The returned value is the number of seconds until expiry.
367 If the response does not contain an \*(L"Expires\*(R" or a \*(L"Cache\-Control\*(R"
368 header, then this function will apply some simple heuristic based on
369 the \*(L"Last\-Modified\*(R" header to determine a suitable lifetime. The
370 following options might be passed to control the heuristics:
372 .ie n .IP "heuristic_expiry => $bool" 4
373 .el .IP "heuristic_expiry => \f(CW$bool\fR" 4
374 .IX Item "heuristic_expiry => $bool"
375 If passed as a \s-1FALSE\s0 value, don't apply heuristics and just return
376 \&\f(CW\*(C`undef\*(C'\fR when \*(L"Expires\*(R" or \*(L"Cache\-Control\*(R" is lacking.
377 .ie n .IP "h_lastmod_fraction => $num" 4
378 .el .IP "h_lastmod_fraction => \f(CW$num\fR" 4
379 .IX Item "h_lastmod_fraction => $num"
380 This number represent the fraction of the difference since the
381 \&\*(L"Last\-Modified\*(R" timestamp to make the expiry time. The default is
382 \&\f(CW0.10\fR, the suggested typical setting of 10% in \s-1RFC\s0 2616.
383 .ie n .IP "h_min => $sec" 4
384 .el .IP "h_min => \f(CW$sec\fR" 4
385 .IX Item "h_min => $sec"
386 This is the lower limit of the heuristic expiry age to use. The
387 default is \f(CW60\fR (1 minute).
388 .ie n .IP "h_max => $sec" 4
389 .el .IP "h_max => \f(CW$sec\fR" 4
390 .IX Item "h_max => $sec"
391 This is the upper limit of the heuristic expiry age to use. The
392 default is \f(CW86400\fR (24 hours).
393 .ie n .IP "h_default => $sec" 4
394 .el .IP "h_default => \f(CW$sec\fR" 4
395 .IX Item "h_default => $sec"
396 This is the expiry age to use when nothing else applies. The default
397 is \f(CW3600\fR (1 hour) or \*(L"h_min\*(R" if greater.
401 .ie n .IP "$r\->is_fresh( %opt )" 4
402 .el .IP "$r\->is_fresh( \f(CW%opt\fR )" 4
403 .IX Item "$r->is_fresh( %opt )"
404 Returns \s-1TRUE\s0 if the response is fresh, based on the values of
405 \&\fIfreshness_lifetime()\fR and \fIcurrent_age()\fR. If the response is no longer
406 fresh, then it has to be re-fetched or re-validated by the origin
409 Options might be passed to control expiry heuristics, see the
410 description of \fIfreshness_lifetime()\fR.
411 .ie n .IP "$r\->fresh_until( %opt )" 4
412 .el .IP "$r\->fresh_until( \f(CW%opt\fR )" 4
413 .IX Item "$r->fresh_until( %opt )"
414 Returns the time (seconds since epoch) when this entity is no longer fresh.
416 Options might be passed to control expiry heuristics, see the
417 description of \fIfreshness_lifetime()\fR.
419 .IX Header "SEE ALSO"
420 HTTP::Headers, HTTP::Message, HTTP::Status, HTTP::Request
422 .IX Header "COPYRIGHT"
423 Copyright 1995\-2004 Gisle Aas.
425 This library is free software; you can redistribute it and/or
426 modify it under the same terms as Perl itself.