1HTTP::Cookies(3)      User Contributed Perl Documentation     HTTP::Cookies(3)
2
3
4

NAME

6       HTTP::Cookies - HTTP cookie jars
7

SYNOPSIS

9         use HTTP::Cookies;
10         $cookie_jar = HTTP::Cookies->new(
11           file => "$ENV{'HOME'}/lwp_cookies.dat",
12           autosave => 1,
13         );
14
15         use LWP;
16         my $browser = LWP::UserAgent->new;
17         $browser->cookie_jar($cookie_jar);
18
19       Or for an empty and temporary cookie jar:
20
21         use LWP;
22         my $browser = LWP::UserAgent->new;
23         $browser->cookie_jar( {} );
24

DESCRIPTION

26       This class is for objects that represent a "cookie jar" -- that is, a
27       database of all the HTTP cookies that a given LWP::UserAgent object
28       knows about.
29
30       Cookies are a general mechanism which server side connections can use
31       to both store and retrieve information on the client side of the
32       connection.  For more information about cookies refer to
33       <URL:http://curl.haxx.se/rfc/cookie_spec.html> and
34       <URL:http://www.cookiecentral.com/>.  This module also implements the
35       new style cookies described in RFC 2965.  The two variants of cookies
36       are supposed to be able to coexist happily.
37
38       Instances of the class HTTP::Cookies are able to store a collection of
39       Set-Cookie2: and Set-Cookie: headers and are able to use this
40       information to initialize Cookie-headers in HTTP::Request objects.  The
41       state of a HTTP::Cookies object can be saved in and restored from
42       files.
43

METHODS

45       The following methods are provided:
46
47       $cookie_jar = HTTP::Cookies->new
48           The constructor takes hash style parameters.  The following
49           parameters are recognized:
50
51             file:            name of the file to restore cookies from and save cookies to
52             autosave:        save during destruction (bool)
53             ignore_discard:  save even cookies that are requested to be discarded (bool)
54             hide_cookie2:    do not add Cookie2 header to requests
55
56           Future parameters might include (not yet implemented):
57
58             max_cookies               300
59             max_cookies_per_domain    20
60             max_cookie_size           4096
61
62             no_cookies   list of domain names that we never return cookies to
63
64       $cookie_jar->add_cookie_header( $request )
65           The add_cookie_header() method will set the appropriate
66           Cookie:-header for the HTTP::Request object given as argument.  The
67           $request must have a valid url attribute before this method is
68           called.
69
70       $cookie_jar->extract_cookies( $response )
71           The extract_cookies() method will look for Set-Cookie: and
72           Set-Cookie2: headers in the HTTP::Response object passed as
73           argument.  Any of these headers that are found are used to update
74           the state of the $cookie_jar.
75
76       $cookie_jar->set_cookie( $version, $key, $val, $path, $domain, $port,
77       $path_spec, $secure, $maxage, $discard, \%rest )
78           The set_cookie() method updates the state of the $cookie_jar.  The
79           $key, $val, $domain, $port and $path arguments are strings.  The
80           $path_spec, $secure, $discard arguments are boolean values. The
81           $maxage value is a number indicating number of seconds that this
82           cookie will live.  A value <= 0 will delete this cookie.  %rest
83           defines various other attributes like "Comment" and "CommentURL".
84
85       $cookie_jar->save
86       $cookie_jar->save( $file )
87           This method file saves the state of the $cookie_jar to a file.  The
88           state can then be restored later using the load() method.  If a
89           filename is not specified we will use the name specified during
90           construction.  If the attribute ignore_discard is set, then we will
91           even save cookies that are marked to be discarded.
92
93           The default is to save a sequence of "Set-Cookie3" lines.
94           "Set-Cookie3" is a proprietary LWP format, not known to be
95           compatible with any browser.  The HTTP::Cookies::Netscape sub-class
96           can be used to save in a format compatible with Netscape.
97
98       $cookie_jar->load
99       $cookie_jar->load( $file )
100           This method reads the cookies from the file and adds them to the
101           $cookie_jar.  The file must be in the format written by the save()
102           method.
103
104       $cookie_jar->revert
105           This method empties the $cookie_jar and re-loads the $cookie_jar
106           from the last save file.
107
108       $cookie_jar->clear
109       $cookie_jar->clear( $domain )
110       $cookie_jar->clear( $domain, $path )
111       $cookie_jar->clear( $domain, $path, $key )
112           Invoking this method without arguments will empty the whole
113           $cookie_jar.  If given a single argument only cookies belonging to
114           that domain will be removed.  If given two arguments, cookies
115           belonging to the specified path within that domain are removed.  If
116           given three arguments, then the cookie with the specified key, path
117           and domain is removed.
118
119       $cookie_jar->clear_temporary_cookies
120           Discard all temporary cookies. Scans for all cookies in the jar
121           with either no expire field or a true "discard" flag. To be called
122           when the user agent shuts down according to RFC 2965.
123
124       $cookie_jar->scan( \&callback )
125           The argument is a subroutine that will be invoked for each cookie
126           stored in the $cookie_jar.  The subroutine will be invoked with the
127           following arguments:
128
129             0  version
130             1  key
131             2  val
132             3  path
133             4  domain
134             5  port
135             6  path_spec
136             7  secure
137             8  expires
138             9  discard
139            10  hash
140
141       $cookie_jar->as_string
142       $cookie_jar->as_string( $skip_discardables )
143           The as_string() method will return the state of the $cookie_jar
144           represented as a sequence of "Set-Cookie3" header lines separated
145           by "\n".  If $skip_discardables is TRUE, it will not return lines
146           for cookies with the Discard attribute.
147

SEE ALSO

149       HTTP::Cookies::Netscape, HTTP::Cookies::Microsoft
150
152       Copyright 1997-2002 Gisle Aas
153
154       This library is free software; you can redistribute it and/or modify it
155       under the same terms as Perl itself.
156
157
158
159perl v5.12.4                      2010-09-20                  HTTP::Cookies(3)
Impressum