Manual Pages for UNIX Darwin command on man HTTP::Cookies
MyWebUniversity

Manual Pages for UNIX Darwin command on man HTTP::Cookies

HTTP::Cookies(3) User Contributed Perl Documentation HTTP::Cookies(3)

NAME

HTTP::Cookies - HTTP cookie jars

SYNOPSIS

use HTTP::Cookies;

$cookiejar = HTTP::Cookies->new(

file => "$ENV{'HOME'}/lwpcookies.dat',

autosave => 1, ); use LWP;

my $browser = LWP::UserAgent->new;

$browser->cookiejar($cookiejar);

Or for an empty and temporary cookie jar: use LWP;

my $browser = LWP::UserAgent->new;

$browser->cookiejar( {} );

DESCRIPTION

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 and . 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. MMEETTHHOODDSS The following methods are provided:

$cookiejar = HTTP::Cookies->new

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) ignorediscard: save even cookies that are requested to be discarded (bool) hidecookie2: do not add Cookie2 header to requests Future parameters might include (not yet implemented): maxcookies 300 maxcookiesperdomain 20 maxcookiesize 4096 nocookies list of domain names that we never return cookies to

$cookiejar->addcookieheader( $request )

The addcookieheader() method will set the appropriate

Cookie:-header for the HTTP::Request object given as argument. The

$request must have a valid url attribute before this method is

called.

$cookiejar->extractcookies( $response )

The extractcookies() method will look for Set-Cookie: and

Set-Cookie2: headers in the HTTP::Response object passed as

argument. Any of these headers that are found are used to update

the state of the $cookiejar.

$cookiejar->setcookie( $version, $key, $val, $path, $domain, $port,

$pathspec, $secure, $maxage, $discard, \%rest )

The setcookie() method updates the state of the $cookiejar. The

$key, $val, $domain, $port and $path arguments are strings. The

$pathspec, $secure, $discard arguments are boolean values. The

$maxage value is a number indicating number of seconds that this

cookie will live. A value <= 0 will delete this cookie. %rest

defines various other attributes like "Comment" and "CommentURL".

$cookiejar->save

$cookiejar->save( $file )

This method file saves the state of the $cookiejar 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 ignorediscard 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.

$cookiejar->load

$cookiejar->load( $file )

This method reads the cookies from the file and adds them to the

$cookiejar. The file must be in the format written by the save()

method.

$cookiejar->revert

This method empties the $cookiejar and re-loads the $cookiejar

from the last save file.

$cookiejar->clear

$cookiejar->clear( $domain )

$cookiejar->clear( $domain, $path )

$cookiejar->clear( $domain, $path, $key )

Invoking this method without arguments will empty the whole

$cookiejar. If given a single argument only cookies belonging to

that domain will be removed. If given two arguments, cookies belonging to the specified path within that domain are removed. If given three arguments, then the cookie with the specified key, path and domain is removed.

$cookiejar->cleartemporarycookies

Discard all temporary cookies. Scans for all cookies in the jar with either no expire field or a true "discard" flag. To be called when the user agent shuts down according to RFC 2965.

$cookiejar->scan( \&callback )

The argument is a subroutine that will be invoked for each cookie

stored in the $cookiejar. The subroutine will be invoked with the

following arguments: 0 version 1 key 2 val 3 path 4 domain 5 port 6 pathspec 7 secure 8 expires 9 discard 10 hash

$cookiejar->asstring

$cookiejar->asstring( $skipdiscardables )

The asstring() method will return the state of the $cookiejar

represented as a sequence of "Set-Cookie3" header lines separated

by "\n". If $skipdiscardables is TRUE, it will not return lines

for cookies with the Discard attribute.

SEE ALSO

HTTP::Cookies::Netscape, HTTP::Cookies::Microsoft

COPYRIGHT

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.

perl v5.8.8 2004-11-12 HTTP::Cookies(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™