{
    "content": [
        {
            "type": "text",
            "text": "# HTTP::Response (perldoc)\n\n**Summary:** HTTP::Response - HTTP style response message\n\n**Synopsis:** Response objects are returned by the request() method of the\n\"LWP::UserAgent\":\n# ...\n$response = $ua->request($request);\nif ($response->issuccess) {\nprint $response->decodedcontent;\n}\nelse {\nprint STDERR $response->statusline, \"\\n\";\n}\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **VERSION** (2 lines)\n- **SYNOPSIS** (12 lines)\n- **DESCRIPTION** (210 lines)\n- **SEE ALSO** (2 lines)\n- **AUTHOR** (2 lines)\n- **COPYRIGHT AND LICENSE** (5 lines)\n\n## Full Content\n\n### NAME\n\nHTTP::Response - HTTP style response message\n\n### VERSION\n\nversion 6.36\n\n### SYNOPSIS\n\nResponse objects are returned by the request() method of the\n\"LWP::UserAgent\":\n\n# ...\n$response = $ua->request($request);\nif ($response->issuccess) {\nprint $response->decodedcontent;\n}\nelse {\nprint STDERR $response->statusline, \"\\n\";\n}\n\n### DESCRIPTION\n\nThe \"HTTP::Response\" class encapsulates HTTP style responses. A response\nconsists of a response line, some headers, and a content body. Note that\nthe LWP library uses HTTP style responses even for non-HTTP protocol\nschemes. Instances of this class are usually created and returned by the\nrequest() method of an \"LWP::UserAgent\" object.\n\n\"HTTP::Response\" is a subclass of \"HTTP::Message\" and therefore inherits\nits methods. The following additional methods are available:\n\n$r = HTTP::Response->new( $code )\n$r = HTTP::Response->new( $code, $msg )\n$r = HTTP::Response->new( $code, $msg, $header )\n$r = HTTP::Response->new( $code, $msg, $header, $content )\nConstructs a new \"HTTP::Response\" object describing a response with\nresponse code $code and optional message $msg. The optional $header\nargument should be a reference to an \"HTTP::Headers\" object or a\nplain array reference of key/value pairs. The optional $content\nargument should be a string of bytes. The meanings of these\narguments are described below.\n\n$r = HTTP::Response->parse( $str )\nThis constructs a new response object by parsing the given string.\n\n$r->code\n$r->code( $code )\nThis is used to get/set the code attribute. The code is a 3 digit\nnumber that encode the overall outcome of an HTTP response. The\n\"HTTP::Status\" module provide constants that provide mnemonic names\nfor the code attribute.\n\n$r->message\n$r->message( $message )\nThis is used to get/set the message attribute. The message is a\nshort human readable single line string that explains the response\ncode.\n\n$r->header( $field )\n$r->header( $field => $value )\nThis is used to get/set header values and it is inherited from\n\"HTTP::Headers\" via \"HTTP::Message\". See HTTP::Headers for details\nand other similar methods that can be used to access the headers.\n\n$r->content\n$r->content( $bytes )\nThis is used to get/set the raw content and it is inherited from the\n\"HTTP::Message\" base class. See HTTP::Message for details and other\nmethods that can be used to access the content.\n\n$r->decodedcontent( %options )\nThis will return the content after any \"Content-Encoding\" and\ncharsets have been decoded. See HTTP::Message for details.\n\n$r->request\n$r->request( $request )\nThis is used to get/set the request attribute. The request attribute\nis a reference to the request that caused this response. It does not\nhave to be the same request passed to the $ua->request() method,\nbecause there might have been redirects and authorization retries in\nbetween.\n\n$r->previous\n$r->previous( $response )\nThis is used to get/set the previous attribute. The previous\nattribute is used to link together chains of responses. You get\nchains of responses if the first response is redirect or\nunauthorized. The value is \"undef\" if this is the first response in\na chain.\n\nNote that the method $r->redirects is provided as a more convenient\nway to access the response chain.\n\n$r->statusline\nReturns the string \"<code> <message>\". If the message attribute is\nnot set then the official name of <code> (see HTTP::Status) is\nsubstituted.\n\n$r->base\nReturns the base URI for this response. The return value will be a\nreference to a URI object.\n\nThe base URI is obtained from one the following sources (in priority\norder):\n\n1.  Embedded in the document content, for instance <BASE HREF=\"...\">\nin HTML documents.\n\n2.  A \"Content-Base:\" or a \"Content-Location:\" header in the\nresponse.\n\nFor backwards compatibility with older HTTP implementations we\nwill also look for the \"Base:\" header.\n\n3.  The URI used to request this response. This might not be the\noriginal URI that was passed to $ua->request() method, because\nwe might have received some redirect responses first.\n\nIf none of these sources provide an absolute URI, undef is returned.\n\nWhen the LWP protocol modules produce the HTTP::Response object,\nthen any base URI embedded in the document (step 1) will already\nhave initialized the \"Content-Base:\" header. (See \"parsehead\" in\nLWP::UserAgent). This means that this method only performs the last\n2 steps (the content is not always available either).\n\n$r->filename\nReturns a filename for this response. Note that doing sanity checks\non the returned filename (eg. removing characters that cannot be\nused on the target filesystem where the filename would be used, and\nlaundering it for security purposes) are the caller's\nresponsibility; the only related thing done by this method is that\nit makes a simple attempt to return a plain filename with no\npreceding path segments.\n\nThe filename is obtained from one the following sources (in priority\norder):\n\n1.  A \"Content-Disposition:\" header in the response. Proper decoding\nof RFC 2047 encoded filenames requires the \"MIME::QuotedPrint\"\n(for \"Q\" encoding), \"MIME::Base64\" (for \"B\" encoding), and\n\"Encode\" modules.\n\n2.  A \"Content-Location:\" header in the response.\n\n3.  The URI used to request this response. This might not be the\noriginal URI that was passed to $ua->request() method, because\nwe might have received some redirect responses first.\n\nIf a filename cannot be derived from any of these sources, undef is\nreturned.\n\n$r->asstring\n$r->asstring( $eol )\nReturns a textual representation of the response.\n\n$r->isinfo\n$r->issuccess\n$r->isredirect\n$r->iserror\n$r->isclienterror\n$r->isservererror\nThese methods indicate if the response was informational,\nsuccessful, a redirection, or an error. See HTTP::Status for the\nmeaning of these.\n\n$r->errorasHTML\nReturns a string containing a complete HTML document indicating what\nerror occurred. This method should only be called when $r->iserror\nis TRUE.\n\n$r->redirects\nReturns the list of redirect responses that lead up to this response\nby following the $r->previous chain. The list order is oldest first.\n\nIn scalar context return the number of redirect responses leading up\nto this one.\n\n$r->currentage\nCalculates the \"current age\" of the response as specified by RFC\n2616 section 13.2.3. The age of a response is the time since it was\nsent by the origin server. The returned value is a number\nrepresenting the age in seconds.\n\n$r->freshnesslifetime( %opt )\nCalculates the \"freshness lifetime\" of the response as specified by\nRFC 2616 section 13.2.4. The \"freshness lifetime\" is the length of\ntime between the generation of a response and its expiration time.\nThe returned value is the number of seconds until expiry.\n\nIf the response does not contain an \"Expires\" or a \"Cache-Control\"\nheader, then this function will apply some simple heuristic based on\nthe \"Last-Modified\" header to determine a suitable lifetime. The\nfollowing options might be passed to control the heuristics:\n\nheuristicexpiry => $bool\nIf passed as a FALSE value, don't apply heuristics and just\nreturn \"undef\" when \"Expires\" or \"Cache-Control\" is lacking.\n\nhlastmodfraction => $num\nThis number represent the fraction of the difference since the\n\"Last-Modified\" timestamp to make the expiry time. The default\nis 0.10, the suggested typical setting of 10% in RFC 2616.\n\nhmin => $sec\nThis is the lower limit of the heuristic expiry age to use. The\ndefault is 60 (1 minute).\n\nhmax => $sec\nThis is the upper limit of the heuristic expiry age to use. The\ndefault is 86400 (24 hours).\n\nhdefault => $sec\nThis is the expiry age to use when nothing else applies. The\ndefault is 3600 (1 hour) or \"hmin\" if greater.\n\n$r->isfresh( %opt )\nReturns TRUE if the response is fresh, based on the values of\nfreshnesslifetime() and currentage(). If the response is no longer\nfresh, then it has to be re-fetched or re-validated by the origin\nserver.\n\nOptions might be passed to control expiry heuristics, see the\ndescription of freshnesslifetime().\n\n$r->freshuntil( %opt )\nReturns the time (seconds since epoch) when this entity is no longer\nfresh.\n\nOptions might be passed to control expiry heuristics, see the\ndescription of freshnesslifetime().\n\n### SEE ALSO\n\nHTTP::Headers, HTTP::Message, HTTP::Status, HTTP::Request\n\n### AUTHOR\n\nGisle Aas <gisle@activestate.com>\n\n### COPYRIGHT AND LICENSE\n\nThis software is copyright (c) 1994 by Gisle Aas.\n\nThis is free software; you can redistribute it and/or modify it under\nthe same terms as the Perl 5 programming language system itself.\n\n"
        }
    ],
    "structuredContent": {
        "command": "HTTP::Response",
        "section": "",
        "mode": "perldoc",
        "summary": "HTTP::Response - HTTP style response message",
        "synopsis": "Response objects are returned by the request() method of the\n\"LWP::UserAgent\":\n# ...\n$response = $ua->request($request);\nif ($response->issuccess) {\nprint $response->decodedcontent;\n}\nelse {\nprint STDERR $response->statusline, \"\\n\";\n}",
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 210,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}