{
    "mode": "perldoc",
    "parameter": "HTTP::CookieJar",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/HTTP%3A%3ACookieJar/json",
    "generated": "2026-10-06T12:22:30Z",
    "synopsis": "use HTTP::CookieJar;\nmy $jar = HTTP::CookieJar->new;\n# add cookie received from a request\n$jar->add( \"http://www.example.com/\", \"CUSTOMER=WILEECOYOTE; Path=/; Domain=example.com\" );\n# extract cookie header for a given request\nmy $cookie = $jar->cookieheader( \"http://www.example.com/\" );",
    "sections": {
        "NAME": {
            "content": "HTTP::CookieJar - A minimalist HTTP user agent cookie jar\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 0.014\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use HTTP::CookieJar;\n\nmy $jar = HTTP::CookieJar->new;\n\n# add cookie received from a request\n$jar->add( \"http://www.example.com/\", \"CUSTOMER=WILEECOYOTE; Path=/; Domain=example.com\" );\n\n# extract cookie header for a given request\nmy $cookie = $jar->cookieheader( \"http://www.example.com/\" );\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module implements a minimalist HTTP user agent cookie jar in conformance with RFC 6265\n<http://tools.ietf.org/html/rfc6265>.\n\nUnlike the commonly used HTTP::Cookies module, this module does not require use of HTTP::Request\nand HTTP::Response objects. An LWP-compatible adapter is available as HTTP::CookieJar::LWP.\n",
            "subsections": []
        },
        "CONSTRUCTORS": {
            "content": "new\nmy $jar = HTTP::CookieJar->new;\n\nReturn a new, empty cookie jar\n",
            "subsections": []
        },
        "METHODS": {
            "content": "add\n$jar->add(\n\"http://www.example.com/\", \"lang=en-US; Path=/; Domain=example.com\"\n);\n\nGiven a request URL and a \"Set-Cookie\" header string, attempts to adds the cookie to the jar. If\nthe cookie is expired, instead it deletes any matching cookie from the jar. A \"Max-Age\"\nattribute will be converted to an absolute \"Expires\" attribute.\n\nIt will throw an exception if the request URL is missing or invalid. Returns true if successful\ncookie processing or undef/empty-list on failure.\n\nclear\n$jar->clear\n\nEmpties the cookie jar.\n\ncookiesfor\nmy @cookies = $jar->cookiesfor(\"http://www.example.com/foo/bar\");\n\nGiven a request URL, returns a list of hash references representing cookies that should be sent.\nThe hash references are copies -- changing values will not change the cookies in the jar.\n\nCookies set \"secure\" will only be returned if the request scheme is \"https\". Expired cookies\nwill not be returned.\n\nKeys of a cookie hash reference might include:\n\n*   name -- the name of the cookie\n\n*   value -- the value of the cookie\n\n*   domain -- the domain name to which the cookie applies\n\n*   path -- the path to which the cookie applies\n\n*   expires -- if present, when the cookie expires in epoch seconds\n\n*   secure -- if present, the cookie was set \"Secure\"\n\n*   httponly -- if present, the cookie was set \"HttpOnly\"\n\n*   hostonly -- if present, the cookie may only be used with the domain as a host\n\n*   creationtime -- epoch time when the cookie was first stored\n\n*   lastaccesstime -- epoch time when the cookie was last accessed (i.e. \"now\")\n\nKeep in mind that \"httponly\" means it should only be used in requests and not made available via\nJavascript, etc. This is pretty meaningless for Perl user agents.\n\nGenerally, user agents should use the \"cookieheader\" method instead.\n\nIt will throw an exception if the request URL is missing or invalid.\n\ncookieheader\nmy $header = $jar->cookieheader(\"http://www.example.com/foo/bar\");\n\nGiven a request URL, returns a correctly-formatted string with all relevant cookies for the\nrequest. This string is ready to be used in a \"Cookie\" header in an HTTP request. E.g.:\n\nSID=31d4d96e407aad42; lang=en-US\n\nIt follows the same exclusion rules as \"cookiesfor\".\n\nIf the request is invalid or no cookies apply, it will return an empty string.\n\ndumpcookies\nmy @list = $jar->dumpcookies;\nmy @list = $jar->dumpcookies( { persistent => 1 } );\n\nReturns a list of raw cookies in string form. The strings resemble what would be received from\n\"Set-Cookie\" headers, but with additional internal fields. The list is only intended for use\nwith \"loadcookies\" to allow cookie jar persistence.\n\nIf a hash reference with a true \"persistent\" key is given as an argument, cookies without an\n\"Expires\" time (i.e. \"session cookies\") will be omitted.\n\nHere is a trivial example of saving a cookie jar file with Path::Tiny:\n\npath(\"jar.txt\")->spew( join \"\\n\", $jar->dumpcookies );\n\nloadcookies\n$jar->loadcookies( @cookies );\n\nGiven a list of cookie strings from \"dumpcookies\", it adds them to the cookie jar. Cookies\nadded in this way will supersede any existing cookies with similar domain, path and name.\n\nIt returns the jar object for convenience when loading a new object:\n\nmy $jar = HTTP::CookieJar->new->loadcookies( @cookies );\n\nHere is a trivial example of loading a cookie jar file with Path::Tiny:\n\nmy $jar = HTTP::CookieJar->new->loadcookies(\npath(\"jar.txt\")->lines\n);\n",
            "subsections": []
        },
        "LIMITATIONS AND CAVEATS": {
            "content": "RFC 6265 vs prior standards\nThis modules adheres as closely as possible to the user-agent rules of RFC 6265. Therefore, it\ndoes not handle nor generate \"Set-Cookie2\" and \"Cookie2\" headers, implement \".local\" suffixes,\nor do path/domain matching in accord with prior RFC's.\n",
            "subsections": [
                {
                    "name": "Internationalized domain names",
                    "content": "Internationalized domain names given in requests must be properly encoded in ASCII form.\n"
                },
                {
                    "name": "Public suffixes",
                    "content": "If Mozilla::PublicSuffix is installed, cookie domains will be checked against the public suffix\nlist. Public suffix cookies are only allowed as host-only cookies.\n"
                },
                {
                    "name": "Third-party cookies",
                    "content": "According to RFC 6265, a cookie may be accepted only if has no \"Domain\" attribute (in which case\nit is \"host-only\") or if the \"Domain\" attribute is a suffix of the request URL. This effectively\nprohibits Site A from setting a cookie for unrelated Site B, which is one potential third-party\ncookie vector.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "*   HTTP::Cookies\n\n*   Mojo::UserAgent::CookieJar\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Bugs / Feature Requests\nPlease report any bugs or feature requests through the issue tracker at\n<https://github.com/dagolden/HTTP-CookieJar/issues>. You will be notified automatically of any\nprogress on your issue.\n",
            "subsections": [
                {
                    "name": "Source Code",
                    "content": "This is open source software. The code repository is available for public review and\ncontribution under the terms of the license.\n\n<https://github.com/dagolden/HTTP-CookieJar>\n\ngit clone https://github.com/dagolden/HTTP-CookieJar.git\n"
                }
            ]
        },
        "AUTHOR": {
            "content": "David Golden <dagolden@cpan.org>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Dan Book <grinnz@grinnz.com>\n\n*   David Golden <xdg@xdg.me>\n\n*   jvolkening <jdv@base2bio.com>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is Copyright (c) 2013 by David Golden.\n\nThis is free software, licensed under:\n\nThe Apache License, Version 2.0, January 2004\n",
            "subsections": []
        }
    },
    "summary": "HTTP::CookieJar - A minimalist HTTP user agent cookie jar",
    "flags": [],
    "examples": [],
    "see_also": []
}