home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _adfa4d7ea4d64a7da96beea2931a081d < prev    next >
Text File  |  2000-03-23  |  8KB  |  196 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>HTTP::Cookies - Cookie storage and management</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> HTTP::Cookies - Cookie storage and management</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#methods">METHODS</A></LI>
  26.     <LI><A HREF="#sub classes">SUB CLASSES</A></LI>
  27.     <LI><A HREF="#copyright">COPYRIGHT</A></LI>
  28. </UL>
  29. <!-- INDEX END -->
  30.  
  31. <HR>
  32. <P>
  33. <H1><A NAME="name">NAME</A></H1>
  34. <P>HTTP::Cookies - Cookie storage and management</P>
  35. <P>
  36. <HR>
  37. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  38. <UL>
  39. <LI>Linux</LI>
  40. <LI>Solaris</LI>
  41. <LI>Windows</LI>
  42. </UL>
  43. <HR>
  44. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  45. <PRE>
  46.  use HTTP::Cookies;
  47.  $cookie_jar = HTTP::Cookies->new;</PRE>
  48. <PRE>
  49.  $cookie_jar->add_cookie_header($request);
  50.  $cookie_jar->extract_cookies($response);</PRE>
  51. <P>
  52. <HR>
  53. <H1><A NAME="description">DESCRIPTION</A></H1>
  54. <P>Cookies are a general mechanism which server side connections can use
  55. to both store and retrieve information on the client side of the
  56. connection.  For more information about cookies refer to
  57. <URL:http://www.netscape.com/newsref/std/cookie_spec.html> and
  58. <URL:http://www.cookiecentral.com/>.  This module also implements the
  59. new style cookies described in <EM>draft-ietf-http-state-man-mec-08.txt</EM>.
  60. The two variants of cookies are supposed to be able to coexist happily.</P>
  61. <P>Instances of the class <EM>HTTP::Cookies</EM> are able to store a collection
  62. of Set-Cookie2: and Set-Cookie: headers and are able to use this
  63. information to initialize Cookie-headers in <EM>HTTP::Request</EM> objects.
  64. The state of a <EM>HTTP::Cookies</EM> object can be saved in and restored from
  65. files.</P>
  66. <P>
  67. <HR>
  68. <H1><A NAME="methods">METHODS</A></H1>
  69. <P>The following methods are provided:</P>
  70. <DL>
  71. <DT><STRONG><A NAME="item_new">$cookie_jar = HTTP::Cookies->new;</A></STRONG><BR>
  72. <DD>
  73. The constructor takes hash style parameters.  The following
  74. parameters are recognized:
  75. <PRE>
  76.   file:            name of the file to restore cookies from and save cookies to
  77.   autosave:        save during destruction (bool)
  78.   ignore_discard:  save even cookies that are requested to be discarded (bool)</PRE>
  79. <P>Future parameters might include (not yet implemented):</P>
  80. <PRE>
  81.   max_cookies               300
  82.   max_cookies_per_domain    20
  83.   max_cookie_size           4096</PRE>
  84. <PRE>
  85.   no_cookies   list of domain names that we never return cookies to</PRE>
  86. <P></P>
  87. <DT><STRONG><A NAME="item_add_cookie_header">$cookie_jar->add_cookie_header($request);</A></STRONG><BR>
  88. <DD>
  89. The <A HREF="#item_add_cookie_header"><CODE>add_cookie_header()</CODE></A> method will set the appropriate Cookie:-header
  90. for the <EM>HTTP::Request</EM> object given as argument.  The $request must
  91. have a valid url attribute before this method is called.
  92. <P></P>
  93. <DT><STRONG><A NAME="item_extract_cookies">$cookie_jar->extract_cookies($response);</A></STRONG><BR>
  94. <DD>
  95. The <A HREF="#item_extract_cookies"><CODE>extract_cookies()</CODE></A> method will look for Set-Cookie: and
  96. Set-Cookie2: headers in the <EM>HTTP::Response</EM> object passed as
  97. argument.  Any of these headers that are found are used to update
  98. the state of the $cookie_jar.
  99. <P></P>
  100. <DT><STRONG><A NAME="item_set_cookie">$cookie_jar->set_cookie($version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, \%rest)</A></STRONG><BR>
  101. <DD>
  102. The <A HREF="#item_set_cookie"><CODE>set_cookie()</CODE></A> method updates the state of the $cookie_jar.  The
  103. $key, $val, $domain, $port and $path arguments are strings.  The
  104. $path_spec, $secure, $discard arguments are boolean values. The $maxage
  105. value is a number indicating number of seconds that this cookie will
  106. live.  A value <= 0 will delete this cookie.  %rest defines
  107. various other attributes like ``Comment'' and ``CommentURL''.
  108. <P></P>
  109. <DT><STRONG><A NAME="item_save">$cookie_jar->save( [$file] );</A></STRONG><BR>
  110. <DD>
  111. This method file saves the state of the $cookie_jar to a file.
  112. The state can then be restored later using the <A HREF="#item_load"><CODE>load()</CODE></A> method.  If a
  113. filename is not specified we will use the name specified during
  114. construction.  If the attribute <EM>ignore_discared</EM> is set, then we
  115. will even save cookies that are marked to be discarded.
  116. <P>The default is to save a sequence of ``Set-Cookie3'' lines.
  117. ``Set-Cookie3'' is a proprietary LWP format, not known to be compatible
  118. with any browser.  The <EM>HTTP::Cookies::Netscape</EM> sub-class can
  119. be used to save in a format compatible with Netscape.</P>
  120. <P></P>
  121. <DT><STRONG><A NAME="item_load">$cookie_jar->load( [$file] );</A></STRONG><BR>
  122. <DD>
  123. This method reads the cookies from the file and adds them to the
  124. $cookie_jar.  The file must be in the format written by the <A HREF="#item_save"><CODE>save()</CODE></A>
  125. method.
  126. <P></P>
  127. <DT><STRONG><A NAME="item_revert">$cookie_jar->revert;</A></STRONG><BR>
  128. <DD>
  129. This method empties the $cookie_jar and re-loads the $cookie_jar
  130. from the last save file.
  131. <P></P>
  132. <DT><STRONG><A NAME="item_clear">$cookie_jar->clear( [$domain, [$path, [$key] ] ]);</A></STRONG><BR>
  133. <DD>
  134. Invoking this method without arguments will empty the whole
  135. $cookie_jar.  If given a single argument only cookies belonging to
  136. that domain will be removed.  If given two arguments, cookies
  137. belonging to the specified path within that domain are removed.  If
  138. given three arguments, then the cookie with the specified key, path
  139. and domain is removed.
  140. <P></P>
  141. <DT><STRONG><A NAME="item_scan">$cookie_jar->scan( \&callback );</A></STRONG><BR>
  142. <DD>
  143. The argument is a subroutine that will be invoked for each cookie
  144. stored in the $cookie_jar.  The subroutine will be invoked with
  145. the following arguments:
  146. <PRE>
  147.   0  version
  148.   1  key
  149.   2  val
  150.   3  path
  151.   4  domain
  152.   5  port
  153.   6  path_spec
  154.   7  secure
  155.   8  expires
  156.   9  discard
  157.  10  hash</PRE>
  158. <P></P>
  159. <DT><STRONG><A NAME="item_as_string">$cookie_jar->as_string( [$skip_discard] );</A></STRONG><BR>
  160. <DD>
  161. The <A HREF="#item_as_string"><CODE>as_string()</CODE></A> method will return the state of the $cookie_jar
  162. represented as a sequence of ``Set-Cookie3'' header lines separated by
  163. ``\n''.  If $skip_discard is TRUE, it will not return lines for
  164. cookies with the <EM>Discard</EM> attribute.
  165. <P></P></DL>
  166. <P>
  167. <HR>
  168. <H1><A NAME="sub classes">SUB CLASSES</A></H1>
  169. <P>We also provide a subclass called <EM>HTTP::Cookies::Netscape</EM> which
  170. loads and saves Netscape compatible cookie files.  You
  171. should be able to have LWP share Netscape's cookies by constructing
  172. your $cookie_jar like this:</P>
  173. <PRE>
  174.  $cookie_jar = HTTP::Cookies::Netscape->new(
  175.                    File     => "$ENV{HOME}/.netscape/cookies",
  176.                    AutoSave => 1,
  177.                );</PRE>
  178. <P>Please note that the Netscape cookie file format is not able to store
  179. all the information available in the Set-Cookie2 headers, so you will
  180. probably loose some information if you save in this format.</P>
  181. <P>
  182. <HR>
  183. <H1><A NAME="copyright">COPYRIGHT</A></H1>
  184. <P>Copyright 1997-1999 Gisle Aas</P>
  185. <P>This library is free software; you can redistribute it and/or
  186. modify it under the same terms as Perl itself.</P>
  187. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  188. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  189. <STRONG><P CLASS=block> HTTP::Cookies - Cookie storage and management</P></STRONG>
  190. </TD></TR>
  191. </TABLE>
  192.  
  193. </BODY>
  194.  
  195. </HTML>
  196.