HTTP::CookieJar(3)
πͺ HTTP::CookieJar πͺ
okay so bestie, this is the manual page for HTTP::CookieJar(3) from the User Contributed Perl Documentation, and it's literally a minimalist HTTP user agent cookie jar. no cap: tiny module, big cookie energy. πͺβ¨
π NAME π
HTTP::CookieJar β a minimalist HTTP user agent cookie jar. that's the whole name, and honestly? iconic. π
β¨ VERSION β¨
version 0.014 π
π οΈ SYNOPSIS π οΈ
use HTTP::CookieJar;
my $jar = HTTP::CookieJar->new;
# add cookie received from a request
$jar->add( "http://www.example.com/", "CUSTOMER=WILE_E_COYOTE; Path=/; Domain=example.com" );
# extract cookie header for a given request
my $cookie = $jar->cookie_header( "http://www.example.com/" );
πΈ DESCRIPTION πΈ
so this module implements a minimalist HTTP user agent cookie jar in conformance with RFC 6265 (http://tools.ietf.org/html/rfc6265). it's giving βsmall but knows exactly what it's doing.β π
unlike the commonly used HTTP::Cookies module, this module does not require use of HTTP::Request and HTTP::Response objects. an LWP-compatible adapter is available as HTTP::CookieJar::LWP. slay. π
π§ CONSTRUCTORS π§
π new π
my $jar = HTTP::CookieJar->new;
returns a new, empty cookie jar. fresh jar, no crumbs, ready for business. π«Ά
π₯ METHODS π₯
π add π
$jar->add(
"http://www.example.com/", "lang=en-US; Path=/; Domain=example.com"
);
given a request URL and a Set-Cookie header string, it attempts to add the cookie to the jar. if the cookie is expired, it instead deletes any matching cookie from the jar. a Max-Age attribute will be converted to an absolute Expires attribute. the way that expiration math gets handled? lowkey important. β³
it will throw an exception if the request URL is missing or invalid. returns true if successful cookie processing or undef/empty-list on failure. periodt.
π§Ό clear π§Ό
$jar->clear
empties the cookie jar. it's the βnew phone who disβ of cookie storage. π
π¦ cookies_for π¦
my @cookies = $jar->cookies_for("http://www.example.com/foo/bar");
given a request URL, returns a list of hash references representing cookies that should be sent. the hash references are copies β changing values will not change the cookies in the jar. no accidental side-eye mutations, bestie. π
cookies set secure will only be returned if the request scheme is https. expired cookies will not be returned.
keys of a cookie hash reference might include:
nameβ the name of the cookievalueβ the value of the cookiedomainβ the domain name to which the cookie appliespathβ the path to which the cookie appliesexpiresβ if present, when the cookie expires in epoch secondssecureβ if present, the cookie was setSecurehttponlyβ if present, the cookie was setHttpOnlyhostonlyβ if present, the cookie may only be used with the domain as a hostcreation_timeβ epoch time when the cookie was first storedlast_access_timeβ epoch time when the cookie was last accessed (i.e. "now")
keep in mind that httponly means it should only be used in requests and not made available via Javascript, etc. this is pretty meaningless for Perl user agents. ngl, Perl user agents are built different. π
generally, user agents should use the cookie_header method instead.
it will throw an exception if the request URL is missing or invalid.
π cookie_header π
my $header = $jar->cookie_header("http://www.example.com/foo/bar");
given a request URL, returns a correctly-formatted string with all relevant cookies for the request. this string is ready to be used in a Cookie header in an HTTP request. e.g.:
SID=31d4d96e407aad42; lang=en-US
it follows the same exclusion rules as cookies_for.
if the request is invalid or no cookies apply, it will return an empty string. respectful. clean. no notes. β¨
π dump_cookies π
my @list = $jar->dump_cookies;
my @list = $jar->dump_cookies( { persistent => 1 } );
returns a list of raw cookies in string form. the strings resemble what would be received from Set-Cookie headers, but with additional internal fields. the list is only intended for use with load_cookies to allow cookie jar persistence. it's giving βsave your faves for later.β πΎπ
if a hash reference with a true persistent key is given as an argument, cookies without an Expires time (i.e. "session cookies") will be omitted.
here is a trivial example of saving a cookie jar file with Path::Tiny:
path("jar.txt")->spew( join "\n", $jar->dump_cookies );
π¦ load_cookies π¦
$jar->load_cookies( @cookies );
given a list of cookie strings from dump_cookies, it adds them to the cookie jar. cookies added in this way will supersede any existing cookies with similar domain, path and name. new cookie era, same iconic jar. π
it returns the jar object for convenience when loading a new object:
my $jar = HTTP::CookieJar->new->load_cookies( @cookies );
here is a trivial example of loading a cookie jar file with Path::Tiny:
my $jar = HTTP::CookieJar->new->load_cookies(
path("jar.txt")->lines
);
π LIMITATIONS AND CAVEATS π
bestie, this part is the βread the fine printβ corner. it's not mean, it's just honest. π«Ά
π RFC 6265 vs prior standards π
this module adheres as closely as possible to the user-agent rules of RFC 6265. therefore, it does not handle nor generate Set-Cookie2 and Cookie2 headers, implement .local suffixes, or do path/domain matching in accord with prior RFC's. it's very much βnew RFC, new me,β and that's on purpose. π
π¦ Internationalized domain names π¦
internationalized domain names given in requests must be properly encoded in ASCII form. no vibes-based encoding, okay? actual ASCII. π€
πΈ Public suffixes πΈ
if Mozilla::PublicSuffix is installed, cookie domains will be checked against the public suffix list. public suffix cookies are only allowed as host-only cookies. it's giving βboundaries, but make them standards-compliant.β π§
π Third-party cookies π
according to RFC 6265, a cookie may be accepted only if it has no Domain attribute (in which case it is "host-only") or if the Domain attribute is a suffix of the request URL. this effectively prohibits Site A from setting a cookie for unrelated Site B, which is one potential third-party cookie vector. not today, cross-site chaos. π
ββοΈ
π SEE ALSO π
HTTP::CookiesMojo::UserAgent::CookieJar
π«Ά SUPPORT π«Ά
π Bugs / Feature Requests π
please report any bugs or feature requests through the issue tracker at https://github.com/dagolden/HTTP-CookieJar/issues. you will be notified automatically of any progress on your issue. communication? we love to see it. π
π Source Code π
this is open source software. the code repository is available for public review and contribution under the terms of the license.
https://github.com/dagolden/HTTP-CookieJar
git clone https://github.com/dagolden/HTTP-CookieJar.git
π AUTHOR π
David Golden <dagolden@cpan.org> β author icon. π«‘
π CONTRIBUTORS π
- Dan Book
<grinnz@grinnz.com> - David Golden
<xdg@xdg.me> - jvolkening
<jdv@base2bio.com>
π COPYRIGHT AND LICENSE π
this software is Copyright (c) 2013 by David Golden.
this is free software, licensed under:
The Apache License, Version 2.0, January 2004
xoxo, bestie π β this page is HTTP::CookieJar(3), generated with perl v5.42.0 on 2025-07-16. mwah! π
π¦ where this page comes from
- opensuse-leap 16.0: perl-HTTP-CookieJar 0.14.0-160000.1.2 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms