HTTP::Cookies - HTTP cookie jars
use HTTP::Cookies; $cookie_jar = HTTP::Cookies->new( file => "$ENV{'HOME'}/lwp_cookies.dat', autosave => 1, ); use LWP; my $browser = LWP::UserAgent->new; $browser->cookie_jar($cookie_jar);
Or for an empty and temporary cookie jar:
use LWP; my $browser = LWP::UserAgent->new; $browser->cookie_jar( {} );
This class is for objects that represent a "cookie jar" -- that is, a database of all the HTTP cookies that a given LWP::UserAgent object knows about.
Cookies are a general mechanism which server side connections can use to both store and retrieve information on the client side of the connection. For more information about cookies refer to <URL:http://wp.netscape.com/newsref/std/cookie_spec.html> and <URL:http://www.cookiecentral.com/>. This module also implements the new style cookies described in RFC 2965. The two variants of cookies are supposed to be able to coexist happily.
Instances of the class HTTP::Cookies are able to store a collection of Set-Cookie2: and Set-Cookie: headers and are able to use this information to initialize Cookie-headers in HTTP::Request objects. The state of a HTTP::Cookies object can be saved in and restored from files.
The following methods are provided:
The constructor takes hash style parameters. The following parameters are recognized:
file: name of the file to restore cookies from and save cookies to autosave: save during destruction (bool) ignore_discard: save even cookies that are requested to be discarded (bool) hide_cookie2: do not add Cookie2 header to requests
Future parameters might include (not yet implemented):
max_cookies 300 max_cookies_per_domain 20 max_cookie_size 4096 no_cookies list of domain names that we never return cookies to
This method file saves the state of the $cookie_jar to a file. The state can then be restored later using the load() method. If a filename is not specified we will use the name specified during construction. If the attribute ignore_discard is set, then we will even save cookies that are marked to be discarded.
The default is to save a sequence of "Set-Cookie3" lines. "Set-Cookie3" is a proprietary LWP format, not known to be compatible with any browser. The HTTP::Cookies::Netscape sub-class can be used to save in a format compatible with Netscape.
discard
flag. To be
called when the user agent shuts down according to RFC 2965.
The argument is a subroutine that will be invoked for each cookie stored in the $cookie_jar. The subroutine will be invoked with the following arguments:
0 version 1 key 2 val 3 path 4 domain 5 port 6 path_spec 7 secure 8 expires 9 discard 10 hash
HTTP::Cookies::Netscape, HTTP::Cookies::Microsoft
Copyright 1997-2002 Gisle Aas
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.