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       <https://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 ($cookie) {
47           return undef unless my $domain = $cookie->domain;
48           return $domain eq 'com' || $domain eq 'net' || $domain eq 'org';
49         });
50
51   max_cookie_size
52         my $size = $jar->max_cookie_size;
53         $jar     = $jar->max_cookie_size(4096);
54
55       Maximum cookie size in bytes, defaults to 4096 (4KiB).
56

METHODS

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

SEE ALSO

99       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
100
101
102
103perl v5.32.1                      2021-02-07     Mojo::UserAgent::CookieJar(3)
Impressum