[HOME]

Path : /proc/self/root/usr/local/share/man/man3/
Upload :
Current File : //proc/self/root/usr/local/share/man/man3/HTTP::Cookies.3pm

.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
.    if \nF \{
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "HTTP::Cookies 3"
.TH HTTP::Cookies 3 "2017-08-03" "perl v5.16.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
HTTP::Cookies \- HTTP cookie jars
.SH "VERSION"
.IX Header "VERSION"
version 6.04
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 5
\&  use HTTP::Cookies;
\&  $cookie_jar = HTTP::Cookies\->new(
\&    file => "$ENV{\*(AqHOME\*(Aq}/lwp_cookies.dat",
\&    autosave => 1,
\&  );
\&
\&  use LWP;
\&  my $browser = LWP::UserAgent\->new;
\&  $browser\->cookie_jar($cookie_jar);
.Ve
.PP
Or for an empty and temporary cookie jar:
.PP
.Vb 3
\&  use LWP;
\&  my $browser = LWP::UserAgent\->new;
\&  $browser\->cookie_jar( {} );
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This class is for objects that represent a \*(L"cookie jar\*(R" \*(-- that is, a
database of all the \s-1HTTP\s0 cookies that a given LWP::UserAgent object
knows about.
.PP
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://curl.haxx.se/rfc/cookie_spec.html> and
<URL:http://www.cookiecentral.com/>.  This module also implements the
new style cookies described in \s-1RFC 2965\s0 <https://tools.ietf.org/html/rfc2965>.
The two variants of cookies are supposed to be able to coexist happily.
.PP
Instances of the class \fIHTTP::Cookies\fR 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 \fIHTTP::Request\fR objects.
The state of a \fIHTTP::Cookies\fR object can be saved in and restored from
files.
.SH "LIMITATIONS"
.IX Header "LIMITATIONS"
This module does not support Public Suffix <https://publicsuffix.org/> encouraged by a more recent standard, \s-1RFC
6265\s0 <https://tools.ietf.org/html/rfc6265>.
.PP
This module's shortcomings mean that a malicious Web site can set
cookies to track your user agent across all sites under a top level
domain.  See \fIt/publicsuffix.t\fR in this module's distribution for
details.
.PP
HTTP::CookieJar::LWP supports Public Suffix, but only provides a
limited subset of this module's functionality and does not
support standards older than
\&\fI\s-1RFC 6265\s0\fR.
.SH "METHODS"
.IX Header "METHODS"
The following methods are provided:
.ie n .IP "$cookie_jar = HTTP::Cookies\->new" 4
.el .IP "\f(CW$cookie_jar\fR = HTTP::Cookies\->new" 4
.IX Item "$cookie_jar = HTTP::Cookies->new"
The constructor takes hash style parameters.  The following
parameters are recognized:
.Sp
.Vb 4
\&  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
.Ve
.Sp
Future parameters might include (not yet implemented):
.Sp
.Vb 3
\&  max_cookies               300
\&  max_cookies_per_domain    20
\&  max_cookie_size           4096
\&
\&  no_cookies   list of domain names that we never return cookies to
.Ve
.ie n .IP "$cookie_jar\->get_cookies( $url_or_domain )" 4
.el .IP "\f(CW$cookie_jar\fR\->get_cookies( \f(CW$url_or_domain\fR )" 4
.IX Item "$cookie_jar->get_cookies( $url_or_domain )"
.PD 0
.ie n .IP "$cookie_jar\->get_cookies( $url_or_domain, $cookie_key,... )" 4
.el .IP "\f(CW$cookie_jar\fR\->get_cookies( \f(CW$url_or_domain\fR, \f(CW$cookie_key\fR,... )" 4
.IX Item "$cookie_jar->get_cookies( $url_or_domain, $cookie_key,... )"
.PD
Returns a hash of the cookies that applies to the given \s-1URL.\s0 If a
domainname is given as argument, then a prefix of \*(L"https://\*(R" is assumed.
.Sp
If one or more \f(CW$cookie_key\fR parameters are provided return the given values,
or \f(CW\*(C`undef\*(C'\fR if the cookie isn't available.
.ie n .IP "$cookie_jar\->add_cookie_header( $request )" 4
.el .IP "\f(CW$cookie_jar\fR\->add_cookie_header( \f(CW$request\fR )" 4
.IX Item "$cookie_jar->add_cookie_header( $request )"
The \fIadd_cookie_header()\fR method will set the appropriate Cookie:\-header
for the \fIHTTP::Request\fR object given as argument.  The \f(CW$request\fR must
have a valid url attribute before this method is called.
.ie n .IP "$cookie_jar\->extract_cookies( $response )" 4
.el .IP "\f(CW$cookie_jar\fR\->extract_cookies( \f(CW$response\fR )" 4
.IX Item "$cookie_jar->extract_cookies( $response )"
The \fIextract_cookies()\fR method will look for Set-Cookie: and
Set\-Cookie2: headers in the \fIHTTP::Response\fR object passed as
argument.  Any of these headers that are found are used to update
the state of the \f(CW$cookie_jar\fR.
.ie n .IP "$cookie_jar\->set_cookie( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, \e%rest )" 4
.el .IP "\f(CW$cookie_jar\fR\->set_cookie( \f(CW$version\fR, \f(CW$key\fR, \f(CW$val\fR, \f(CW$path\fR, \f(CW$domain\fR, \f(CW$port\fR, \f(CW$path_spec\fR, \f(CW$secure\fR, \f(CW$maxage\fR, \f(CW$discard\fR, \e%rest )" 4
.IX Item "$cookie_jar->set_cookie( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, %rest )"
The \fIset_cookie()\fR method updates the state of the \f(CW$cookie_jar\fR.  The
\&\f(CW$key\fR, \f(CW$val\fR, \f(CW$domain\fR, \f(CW$port\fR and \f(CW$path\fR arguments are strings.  The
\&\f(CW$path_spec\fR, \f(CW$secure\fR, \f(CW$discard\fR arguments are boolean values. The \f(CW$maxage\fR
value is a number indicating number of seconds that this cookie will
live.  A value of \f(CW$maxage\fR <= 0 will delete this cookie.  \f(CW%rest\fR defines
various other attributes like \*(L"Comment\*(R" and \*(L"CommentURL\*(R".
.ie n .IP "$cookie_jar\->save" 4
.el .IP "\f(CW$cookie_jar\fR\->save" 4
.IX Item "$cookie_jar->save"
.PD 0
.ie n .IP "$cookie_jar\->save( $file )" 4
.el .IP "\f(CW$cookie_jar\fR\->save( \f(CW$file\fR )" 4
.IX Item "$cookie_jar->save( $file )"
.PD
This method file saves the state of the \f(CW$cookie_jar\fR to a file.
The state can then be restored later using the \fIload()\fR method.  If a
filename is not specified we will use the name specified during
construction.  If the attribute \fIignore_discard\fR is set, then we
will even save cookies that are marked to be discarded.
.Sp
The default is to save a sequence of \*(L"Set\-Cookie3\*(R" lines.
\&\*(L"Set\-Cookie3\*(R" is a proprietary \s-1LWP\s0 format, not known to be compatible
with any browser.  The \fIHTTP::Cookies::Netscape\fR sub-class can
be used to save in a format compatible with Netscape.
.ie n .IP "$cookie_jar\->load" 4
.el .IP "\f(CW$cookie_jar\fR\->load" 4
.IX Item "$cookie_jar->load"
.PD 0
.ie n .IP "$cookie_jar\->load( $file )" 4
.el .IP "\f(CW$cookie_jar\fR\->load( \f(CW$file\fR )" 4
.IX Item "$cookie_jar->load( $file )"
.PD
This method reads the cookies from the file and adds them to the
\&\f(CW$cookie_jar\fR.  The file must be in the format written by the \fIsave()\fR
method.
.ie n .IP "$cookie_jar\->revert" 4
.el .IP "\f(CW$cookie_jar\fR\->revert" 4
.IX Item "$cookie_jar->revert"
This method empties the \f(CW$cookie_jar\fR and re-loads the \f(CW$cookie_jar\fR
from the last save file.
.ie n .IP "$cookie_jar\->clear" 4
.el .IP "\f(CW$cookie_jar\fR\->clear" 4
.IX Item "$cookie_jar->clear"
.PD 0
.ie n .IP "$cookie_jar\->clear( $domain )" 4
.el .IP "\f(CW$cookie_jar\fR\->clear( \f(CW$domain\fR )" 4
.IX Item "$cookie_jar->clear( $domain )"
.ie n .IP "$cookie_jar\->clear( $domain, $path )" 4
.el .IP "\f(CW$cookie_jar\fR\->clear( \f(CW$domain\fR, \f(CW$path\fR )" 4
.IX Item "$cookie_jar->clear( $domain, $path )"
.ie n .IP "$cookie_jar\->clear( $domain, $path, $key )" 4
.el .IP "\f(CW$cookie_jar\fR\->clear( \f(CW$domain\fR, \f(CW$path\fR, \f(CW$key\fR )" 4
.IX Item "$cookie_jar->clear( $domain, $path, $key )"
.PD
Invoking this method without arguments will empty the whole
\&\f(CW$cookie_jar\fR.  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.
.ie n .IP "$cookie_jar\->clear_temporary_cookies" 4
.el .IP "\f(CW$cookie_jar\fR\->clear_temporary_cookies" 4
.IX Item "$cookie_jar->clear_temporary_cookies"
Discard all temporary cookies. Scans for all cookies in the jar
with either no expire field or a true \f(CW\*(C`discard\*(C'\fR flag. To be
called when the user agent shuts down according to \s-1RFC 2965.\s0
.ie n .IP "$cookie_jar\->scan( \e&callback )" 4
.el .IP "\f(CW$cookie_jar\fR\->scan( \e&callback )" 4
.IX Item "$cookie_jar->scan( &callback )"
The argument is a subroutine that will be invoked for each cookie
stored in the \f(CW$cookie_jar\fR.  The subroutine will be invoked with
the following arguments:
.Sp
.Vb 11
\&  0  version
\&  1  key
\&  2  val
\&  3  path
\&  4  domain
\&  5  port
\&  6  path_spec
\&  7  secure
\&  8  expires
\&  9  discard
\& 10  hash
.Ve
.ie n .IP "$cookie_jar\->as_string" 4
.el .IP "\f(CW$cookie_jar\fR\->as_string" 4
.IX Item "$cookie_jar->as_string"
.PD 0
.ie n .IP "$cookie_jar\->as_string( $skip_discardables )" 4
.el .IP "\f(CW$cookie_jar\fR\->as_string( \f(CW$skip_discardables\fR )" 4
.IX Item "$cookie_jar->as_string( $skip_discardables )"
.PD
The \fIas_string()\fR method will return the state of the \f(CW$cookie_jar\fR
represented as a sequence of \*(L"Set\-Cookie3\*(R" header lines separated by
\&\*(L"\en\*(R".  If \f(CW$skip_discardables\fR is \s-1TRUE,\s0 it will not return lines for
cookies with the \fIDiscard\fR attribute.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
HTTP::Cookies::Netscape, HTTP::Cookies::Microsoft
.SH "AUTHOR"
.IX Header "AUTHOR"
Gisle Aas <gisle@activestate.com>
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
This software is copyright (c) 2002\-2017 by Gisle Aas.
.PP
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.