NAME
Mojo::UserAgent::CookieJar - Cookie jar for HTTP user agents
SYNOPSIS
my $jar = Mojo::UserAgent::CookieJar->new;
$jar ->add(
Mojo::Cookie::Response->new(
name => 'foo' ,
value => 'bar' ,
domain => 'localhost' ,
path => '/test'
)
);
say $cookie ->name;
say $cookie ->value;
}
|
DESCRIPTION
Mojo::UserAgent::CookieJar is a minimalistic and relaxed cookie jar used by Mojo::UserAgent, based on RFC 6265.
ATTRIBUTES
Mojo::UserAgent::CookieJar implements the following attributes.
file
my $file = $jar ->file;
$jar = $jar ->file( '/home/sri/cookies.txt' );
|
File to "load" cookies from and "save" cookies to in Netscape format. Note that this attribute is EXPERIMENTAL and might change without warning!
$jar ->file( 'cookies.txt' )->save;
$jar ->file( 'cookies.txt' )->empty->load;
|
ignore
my $ignore = $jar ->ignore;
$jar = $jar ->ignore( sub {...});
|
A callback used to decide if a cookie should be ignored by "collect".
$jar ->ignore( sub { 1 });
$jar ->ignore( sub ( $cookie ) {
return undef unless my $domain = $cookie ->domain;
return $domain eq 'com' || $domain eq 'net' || $domain eq 'org' ;
});
|
max_cookie_size
my $size = $jar ->max_cookie_size;
$jar = $jar ->max_cookie_size(4096);
|
Maximum cookie size in bytes, defaults to 4096
(4KiB).
METHODS
Mojo::UserAgent::CookieJar inherits all methods from Mojo::Base and implements the following new ones.
add
$jar = $jar ->add( @cookies );
|
Add multiple Mojo::Cookie::Response objects to the jar.
all
Return all Mojo::Cookie::Response objects that are currently stored in the jar.
say $_ ->name for @{ $jar ->all};
|
collect
$jar ->collect(Mojo::Transaction::HTTP->new);
|
Collect response cookies from transaction.
empty
Empty the jar.
find
my $cookies = $jar ->find(Mojo::URL->new);
|
Find Mojo::Cookie::Request objects in the jar for Mojo::URL object.
load
Load cookies from "file". Note that this method is EXPERIMENTAL and might change without warning!
prepare
$jar ->prepare(Mojo::Transaction::HTTP->new);
|
Prepare request cookies for transaction.
save
Save cookies to "file". Note that this method is EXPERIMENTAL and might change without warning!
to_string
my $string = $jar ->to_string;
|
Stringify cookies in Netscape format. Note that this method is EXPERIMENTAL and might change without warning!
SEE ALSO
Mojolicious, Mojolicious::Guides, https://mojolicious.org.