1Mojo::UserAgent::CookieUJsaerr(3C)ontributed Perl DocumeMnotjaot:i:oUnserAgent::CookieJar(3)
2
3
4

NAME

6       Mojo::UserAgent::CookieJar - Cookie jar for HTTP user agents
7

SYNOPSIS

9         use Mojo::UserAgent::CookieJar;
10
11         # Add response cookies
12         my $jar = Mojo::UserAgent::CookieJar->new;
13         $jar->add(
14           Mojo::Cookie::Response->new(
15             name   => 'foo',
16             value  => 'bar',
17             domain => 'localhost',
18             path   => '/test'
19           )
20         );
21
22         # Find request cookies
23         for my $cookie (@{$jar->find(Mojo::URL->new('http://localhost/test'))}) {
24           say $cookie->name;
25           say $cookie->value;
26         }
27

DESCRIPTION

29       Mojo::UserAgent::CookieJar is a minimalistic and relaxed cookie jar
30       used by Mojo::UserAgent, based on RFC 6265
31       <http://tools.ietf.org/html/rfc6265>.
32

ATTRIBUTES

34       Mojo::UserAgent::CookieJar implements the following attributes.
35
36   ignore
37         my $ignore = $jar->ignore;
38         $jar       = $jar->ignore(sub {...});
39
40       A callback used to decide if a cookie should be ignored by "collect".
41
42         # Ignore all cookies
43         $jar->ignore(sub { 1 });
44
45         # Ignore cookies for domains "com", "net" and "org"
46         $jar->ignore(sub {
47           my $cookie = shift;
48           return undef unless my $domain = $cookie->domain;
49           return $domain eq 'com' || $domain eq 'net' || $domain eq 'org';
50         });
51
52   max_cookie_size
53         my $size = $jar->max_cookie_size;
54         $jar     = $jar->max_cookie_size(4096);
55
56       Maximum cookie size in bytes, defaults to 4096 (4KiB).
57

METHODS

59       Mojo::UserAgent::CookieJar inherits all methods from Mojo::Base and
60       implements the following new ones.
61
62   add
63         $jar = $jar->add(@cookies);
64
65       Add multiple Mojo::Cookie::Response objects to the jar.
66
67   all
68         my $cookies = $jar->all;
69
70       Return all Mojo::Cookie::Response objects that are currently stored in
71       the jar.
72
73         # Names of all cookies
74         say $_->name for @{$jar->all};
75
76   collect
77         $jar->collect(Mojo::Transaction::HTTP->new);
78
79       Collect response cookies from transaction.
80
81   empty
82         $jar->empty;
83
84       Empty the jar.
85
86   find
87         my $cookies = $jar->find(Mojo::URL->new);
88
89       Find Mojo::Cookie::Request objects in the jar for Mojo::URL object.
90
91         # Names of all cookies found
92         say $_->name for @{$jar->find(Mojo::URL->new('http://example.com/foo'))};
93
94   prepare
95         $jar->prepare(Mojo::Transaction::HTTP->new);
96
97       Prepare request cookies for transaction.
98

SEE ALSO

100       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
101
102
103
104perl v5.32.0                      2020-07-28     Mojo::UserAgent::CookieJar(3)
Impressum