.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .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. \*(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- .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" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTTP::Response 3pm" .TH HTTP::Response 3pm "2021-02-20" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" HTTP::Response \- HTTP style response message .SH "VERSION" .IX Header "VERSION" version 6.28 .SH "SYNOPSIS" .IX Header "SYNOPSIS" Response objects are returned by the \fBrequest()\fR method of the \f(CW\*(C`LWP::UserAgent\*(C'\fR: .PP .Vb 8 \& # ... \& $response = $ua\->request($request); \& if ($response\->is_success) { \& print $response\->decoded_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 \fBrequest()\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 "\f(CW$r\fR = 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, $msg )" 4 .el .IP "\f(CW$r\fR = 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, $msg, $header )" 4 .el .IP "\f(CW$r\fR = 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, $msg, $header, $content )" 4 .el .IP "\f(CW$r\fR = 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 meanings of these arguments are described below. .ie n .IP "$r = HTTP::Response\->parse( $str )" 4 .el .IP "\f(CW$r\fR = 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. .ie n .IP "$r\->code" 4 .el .IP "\f(CW$r\fR\->code" 4 .IX Item "$r->code" .PD 0 .ie n .IP "$r\->code( $code )" 4 .el .IP "\f(CW$r\fR\->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 an \s-1HTTP\s0 response. The \&\f(CW\*(C`HTTP::Status\*(C'\fR module provide constants that provide mnemonic names for the code attribute. .ie n .IP "$r\->message" 4 .el .IP "\f(CW$r\fR\->message" 4 .IX Item "$r->message" .PD 0 .ie n .IP "$r\->message( $message )" 4 .el .IP "\f(CW$r\fR\->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 "\f(CW$r\fR\->header( \f(CW$field\fR )" 4 .IX Item "$r->header( $field )" .PD 0 .ie n .IP "$r\->header( $field => $value )" 4 .el .IP "\f(CW$r\fR\->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. .ie n .IP "$r\->content" 4 .el .IP "\f(CW$r\fR\->content" 4 .IX Item "$r->content" .PD 0 .ie n .IP "$r\->content( $bytes )" 4 .el .IP "\f(CW$r\fR\->content( \f(CW$bytes\fR )" 4 .IX Item "$r->content( $bytes )" .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 "\f(CW$r\fR\->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 have been decoded. See HTTP::Message for details. .ie n .IP "$r\->request" 4 .el .IP "\f(CW$r\fR\->request" 4 .IX Item "$r->request" .PD 0 .ie n .IP "$r\->request( $request )" 4 .el .IP "\f(CW$r\fR\->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 request that caused this response. It does not have to be the same request passed to the \f(CW$ua\fR\->\fBrequest()\fR method, because there might have been redirects and authorization retries in between. .ie n .IP "$r\->previous" 4 .el .IP "\f(CW$r\fR\->previous" 4 .IX Item "$r->previous" .PD 0 .ie n .IP "$r\->previous( $response )" 4 .el .IP "\f(CW$r\fR\->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. .Sp Note that the method \f(CW$r\fR\->redirects is provided as a more convenient way to access the response chain. .ie n .IP "$r\->status_line" 4 .el .IP "\f(CW$r\fR\->status_line" 4 .IX Item "$r->status_line" Returns the string \*(L" \*(R". If the message attribute is not set then the official name of (see HTTP::Status) is substituted. .ie n .IP "$r\->base" 4 .el .IP "\f(CW$r\fR\->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\->\fBrequest()\fR method, because we might have received some redirect responses first. .RE .RS 4 .Sp If none 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. (See \*(L"parse_head\*(R" in LWP::UserAgent). This means that this method only performs the last 2 steps (the content is not always available either). .RE .ie n .IP "$r\->filename" 4 .el .IP "\f(CW$r\fR\->filename" 4 .IX Item "$r->filename" Returns a filename for this response. Note that doing sanity checks on the returned filename (eg. removing characters that cannot be used on the target filesystem where the filename would be used, and laundering it for security purposes) are the caller's responsibility; the only related thing done by this method is that it makes a simple attempt to return a plain filename with no preceding path segments. .Sp The filename is obtained from one the following sources (in priority order): .RS 4 .IP "1." 4 A \*(L"Content-Disposition:\*(R" header in the response. Proper decoding of \&\s-1RFC 2047\s0 encoded filenames requires the \f(CW\*(C`MIME::QuotedPrint\*(C'\fR (for \*(L"Q\*(R" encoding), \f(CW\*(C`MIME::Base64\*(C'\fR (for \*(L"B\*(R" encoding), and \f(CW\*(C`Encode\*(C'\fR modules. .IP "2." 4 A \*(L"Content-Location:\*(R" header in the response. .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\->\fBrequest()\fR method, because we might have received some redirect responses first. .RE .RS 4 .Sp If a filename cannot be derived from any of these sources, undef is returned. .RE .ie n .IP "$r\->as_string" 4 .el .IP "\f(CW$r\fR\->as_string" 4 .IX Item "$r->as_string" .PD 0 .ie n .IP "$r\->as_string( $eol )" 4 .el .IP "\f(CW$r\fR\->as_string( \f(CW$eol\fR )" 4 .IX Item "$r->as_string( $eol )" .PD Returns a textual representation of the response. .ie n .IP "$r\->is_info" 4 .el .IP "\f(CW$r\fR\->is_info" 4 .IX Item "$r->is_info" .PD 0 .ie n .IP "$r\->is_success" 4 .el .IP "\f(CW$r\fR\->is_success" 4 .IX Item "$r->is_success" .ie n .IP "$r\->is_redirect" 4 .el .IP "\f(CW$r\fR\->is_redirect" 4 .IX Item "$r->is_redirect" .ie n .IP "$r\->is_error" 4 .el .IP "\f(CW$r\fR\->is_error" 4 .IX Item "$r->is_error" .ie n .IP "$r\->is_client_error" 4 .el .IP "\f(CW$r\fR\->is_client_error" 4 .IX Item "$r->is_client_error" .ie n .IP "$r\->is_server_error" 4 .el .IP "\f(CW$r\fR\->is_server_error" 4 .IX Item "$r->is_server_error" .PD These methods indicate if the response was informational, successful, a redirection, or an error. See HTTP::Status for the meaning of these. .ie n .IP "$r\->error_as_HTML" 4 .el .IP "\f(CW$r\fR\->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 .ie n .IP "$r\->redirects" 4 .el .IP "\f(CW$r\fR\->redirects" 4 .IX Item "$r->redirects" Returns the list of redirect responses that lead up to this response by following the \f(CW$r\fR\->previous chain. The list order is oldest first. .Sp In scalar context return the number of redirect responses leading up to this one. .ie n .IP "$r\->current_age" 4 .el .IP "\f(CW$r\fR\->current_age" 4 .IX Item "$r->current_age" Calculates the \*(L"current age\*(R" of the response as specified by \s-1RFC 2616\s0 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. .ie n .IP "$r\->freshness_lifetime( %opt )" 4 .el .IP "\f(CW$r\fR\->freshness_lifetime( \f(CW%opt\fR )" 4 .IX Item "$r->freshness_lifetime( %opt )" Calculates the \*(L"freshness lifetime\*(R" of the response as specified by \&\s-1RFC 2616\s0 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 the number of seconds until expiry. .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 the \*(L"Last-Modified\*(R" header to determine a suitable lifetime. The following options might be passed to control the heuristics: .RS 4 .ie n .IP "heuristic_expiry => $bool" 4 .el .IP "heuristic_expiry => \f(CW$bool\fR" 4 .IX Item "heuristic_expiry => $bool" If passed as a \s-1FALSE\s0 value, don't apply heuristics and just return \&\f(CW\*(C`undef\*(C'\fR when \*(L"Expires\*(R" or \*(L"Cache-Control\*(R" is lacking. .ie n .IP "h_lastmod_fraction => $num" 4 .el .IP "h_lastmod_fraction => \f(CW$num\fR" 4 .IX Item "h_lastmod_fraction => $num" This number represent the fraction of the difference since the \&\*(L"Last-Modified\*(R" timestamp to make the expiry time. The default is \&\f(CW0.10\fR, the suggested typical setting of 10% in \s-1RFC 2616.\s0 .ie n .IP "h_min => $sec" 4 .el .IP "h_min => \f(CW$sec\fR" 4 .IX Item "h_min => $sec" This is the lower limit of the heuristic expiry age to use. The default is \f(CW60\fR (1 minute). .ie n .IP "h_max => $sec" 4 .el .IP "h_max => \f(CW$sec\fR" 4 .IX Item "h_max => $sec" This is the upper limit of the heuristic expiry age to use. The default is \f(CW86400\fR (24 hours). .ie n .IP "h_default => $sec" 4 .el .IP "h_default => \f(CW$sec\fR" 4 .IX Item "h_default => $sec" This is the expiry age to use when nothing else applies. The default is \f(CW3600\fR (1 hour) or \*(L"h_min\*(R" if greater. .RE .RS 4 .RE .ie n .IP "$r\->is_fresh( %opt )" 4 .el .IP "\f(CW$r\fR\->is_fresh( \f(CW%opt\fR )" 4 .IX Item "$r->is_fresh( %opt )" Returns \s-1TRUE\s0 if the response is fresh, based on the values of \&\fBfreshness_lifetime()\fR and \fBcurrent_age()\fR. If the response is no longer fresh, then it has to be re-fetched or re-validated by the origin server. .Sp Options might be passed to control expiry heuristics, see the description of \fBfreshness_lifetime()\fR. .ie n .IP "$r\->fresh_until( %opt )" 4 .el .IP "\f(CW$r\fR\->fresh_until( \f(CW%opt\fR )" 4 .IX Item "$r->fresh_until( %opt )" Returns the time (seconds since epoch) when this entity is no longer fresh. .Sp Options might be passed to control expiry heuristics, see the description of \fBfreshness_lifetime()\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" HTTP::Headers, HTTP::Message, HTTP::Status, HTTP::Request .SH "AUTHOR" .IX Header "AUTHOR" Gisle Aas .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 1994 by Gisle Aas. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.