NAME
Fetch::CookieJar - store cookies and apply them to requests
SYNOPSIS
my $ua = Fetch->new(cookie_jar => 1); # auto-create a jar
$ua->post('https://site/login', body => 'u=me&p=secret')->get;
# the Set-Cookie from that response is now sent on later requests:
my $res = $ua->get('https://site/account')->get;
# or manage a jar directly
my $jar = Fetch::CookieJar->new;
$jar->set_cookie('sid=abc; Path=/; Secure', 'site', '/login');
my $cookie = $jar->cookie_header('site', '/account', 1); # "sid=abc"
DESCRIPTION
A cookie store following the practical parts of RFC 6265: it parses Set-Cookie response headers and builds the Cookie header for an outgoing request, honouring Domain (host-only and subdomain matching), Path, Expires / Max-Age and the Secure flag. Cookies are keyed by (domain, path, name).
Give a jar to Fetch with Fetch->new(cookie_jar => $jar) (or cookie_jar => 1 to make a fresh one) and it is applied automatically, including across redirects.
METHODS
set_cookie($set_cookie_value, $host, $request_path)
Parse one Set-Cookie value as if received from $host for $request_path and store it (or delete it, if expired).
extract($response_or_headers, $host, $request_path)
Store every Set-Cookie in a Fetch::Response or Fetch::Headers.
cookie_header($host, $request_path, $secure)
The Cookie header value for a request to $host/$request_path (pass a true $secure for https), or undef if nothing matches.
clear / count / purge
Remove all cookies; how many are stored; drop expired ones.
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION. This is free software, licensed under the Artistic License 2.0.