Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 4921009d9713f60c8e40a1553c853d51 > files > 67

libapreq2-devel-2.13-1.fc14.x86_64.rpm

<html>
<head>
  <link rel="stylesheet" type="text/css" href="dox.css" />
  <title>libapreq2-2.13: libapreq2: Apache2::Cookie</title> 
</head>
<body>
<div id="page-header">
<p class="menu">
   <a href="http://www.apache.org/">Apache Software Foundation</a> &gt; <a href="http://httpd.apache.org">HTTP Server Project</a> &gt;
<a href="http://httpd.apache.org/apreq/">Request Library Subproject</a></p>
<p class="apache">Apache HTTP Server Request Library</p>
<img alt="" src="feather.gif" /></div>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>Apache2::Cookie<br>
<small>
[<a class="el" href="group__apreq__xs.html">Perl</a>]</small>
</h1><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
</table>




<!-- INDEX BEGIN -->
<div name="index">
<p><a name="__index__"></a></p>

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#apache2__cookie__jar">Apache2::Cookie::Jar</a></li>
	<ul>

		<li><a href="#new">new</a></li>
		<li><a href="#cookies">cookies</a></li>
		<li><a href="#status">status</a></li>
	</ul>

	<li><a href="#apache2__cookie">Apache2::Cookie</a></li>
	<ul>

		<li><a href="#new">new</a></li>
		<li><a href="#freeze">freeze</a></li>
		<li><a href="#thaw">thaw</a></li>
		<li><a href="#as_string">as_string</a></li>
		<li><a href="#name">name</a></li>
		<li><a href="#value">value</a></li>
		<li><a href="#raw_value">raw_value</a></li>
		<li><a href="#bake">bake</a></li>
		<li><a href="#bake2">bake2</a></li>
		<li><a href="#domain">domain</a></li>
		<li><a href="#path">path</a></li>
		<li><a href="#version">version</a></li>
		<li><a href="#expires">expires</a></li>
		<li><a href="#secure">secure</a></li>
		<li><a href="#httponly">httponly</a></li>
		<li><a href="#httponly">httponly</a></li>
		<li><a href="#comment">comment</a></li>
		<li><a href="#commenturl">commentURL</a></li>
		<li><a href="#fetch">fetch</a></li>
	</ul>

	<li><a href="#porting_from_1_x">PORTING from 1.X</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
	<li><a href="#copyright">COPYRIGHT</a></li>
</ul>

<hr name="index" />
</div>
<!-- INDEX END -->


<p>

</p>

<h1><a name="name">NAME</a></h1>

<p>Apache2::Cookie, Apache2::Cookie::Jar - HTTP Cookies Class</p>

<p>

</p>
<hr />

<h1><a name="synopsis">SYNOPSIS</a></h1>

<pre>
    use Apache2::Cookie;</pre>

<pre>
    $j = Apache2::Cookie::Jar-&gt;new($r);
    $c_in = $j-&gt;cookies(&quot;foo&quot;);         # get cookie from request headers</pre>

<pre>
    $c_out = Apache2::Cookie-&gt;new($r,
                                  -name  =&gt; &quot;mycookie&quot;,
                                  -value =&gt; $c_in-&gt;name );</pre>

<pre>
    $c_out-&gt;path(&quot;/bar&quot;);               # set path to &quot;/bar&quot;
    $c_out-&gt;bake;                       # send cookie in response headers</pre>

<p>

</p>
<hr />

<h1><a name="description">DESCRIPTION</a></h1>

<p>The Apache2::Cookie module is based on the original 1.X versions, which mimic
the CGI::Cookie API.  The current version of this module includes several packages
and methods which are patterned after Apache2::Request, yet remain largely
backwards-compatible with the original 1.X API (see the <a href="#porting_from_1_x">PORTING from 1.X</a> section
below for known issues).</p>

<p>This manpage documents the Apache2::Cookie and Apache2::Cookie::Jar packages.</p>

<p>

</p>
<hr />

<h1><a name="apache2__cookie__jar">Apache2::Cookie::Jar</a></h1>

<p>This class collects Apache2::Cookie objects into a lookup table.  It plays
the same role for accessing the incoming cookies as Apache2::Request does for
accessing the incoming params and file uploads.</p>

<p>

</p>

<h2><a name="new">new</a></h2>

<pre>
    Apache2::Cookie::Jar-&gt;new($env)</pre>

<p>Class method that retrieves the parsed cookie jar from the current
environment.</p>

<p>

</p>

<h2><a name="cookies">cookies</a></h2>

<pre>
    $jar-&gt;cookies()
    $jar-&gt;cookies($key)</pre>

<p>Retrieve cookies named $key with from the jar object.  In scalar
context the first such cookie is returned, and in list context the
full list of such cookies are returned.</p>

<p>If the $key argument is omitted, <code>scalar $jar-&gt;cookies()</code> will
return an APR::Request::Cookie::Table object containing all the cookies in
the jar.  Modifications to the this object will affect the jar's
internal <em>cookies</em> table in <code>apreq_jar_t</code>, so their impact will
be noticed by all libapreq2 applications during this request.</p>

<p>In list context <code>$jar-&gt;cookies()</code> returns the list of names
for all the cookies in the jar.  The order corresponds to the
order in which the cookies appeared in the incoming &quot;Cookie&quot; header.</p>

<p>This method will throw an <code>APR::Request::Error</code> object into $@ if
the returned value(s) could be unreliable.  In particular, note that
<code>scalar $jar-&gt;cookies(&quot;foo&quot;)</code> will not croak if it can locate
the a &quot;foo&quot; cookie within the jar's parsed cookie table, even if the
cookie parser has failed (the cookies are parsed in the same order
as they appeared in the &quot;Cookie&quot; header). In all other circumstances
<code>cookies</code> will croak if the parser failed to successfully parse the
&quot;Cookie&quot; header.</p>

<pre>
    $c = Apache2::Cookie-&gt;new($r, name =&gt; &quot;foo&quot;, value =&gt; 3);
    $j-&gt;cookies-&gt;add($c);</pre>

<pre>
    $cookie = $j-&gt;cookies(&quot;foo&quot;);  # first foo cookie
    @cookies = $j-&gt;cookies(&quot;foo&quot;); # all foo cookies
    @names = $j-&gt;cookies();        # all cookie names</pre>

<p>

</p>

<h2><a name="status">status</a></h2>

<pre>
    $jar-&gt;status()</pre>

<p>Get the <em>APR</em> status code of the cookie parser:
APR_SUCCESS on success, error otherwise.</p>

<p>

</p>
<hr />

<h1><a name="apache2__cookie">Apache2::Cookie</a></h1>

<p>

</p>

<h2><a name="new">new</a></h2>

<pre>
    Apache2::Cookie-&gt;new($env, %args)</pre>

<p>Just like CGI::Cookie::new, but requires an additional environment argument:</p>

<pre>
    $cookie = Apache2::Cookie-&gt;new($r,
                             -name    =&gt;  'foo',
                             -value   =&gt;  'bar',
                             -expires =&gt;  '+3M',
                             -domain  =&gt;  '.capricorn.com',
                             -path    =&gt;  '/cgi-bin/database',
                             -secure  =&gt;  1
                            );</pre>

<p>The <code>-value</code> argument may be either an arrayref, a hashref, or
a string.  <code>Apache2::Cookie::freeze</code> encodes this argument into the
cookie's raw value.</p>

<p>

</p>

<h2><a name="freeze">freeze</a></h2>

<pre>
    Apache2::Cookie-&gt;freeze($value)</pre>

<p>Helper function (for <a href="#new"><code>new</code></a>) that serializes a new cookie's value in a
manner compatible with CGI::Cookie (and Apache2::Cookie 1.X).  This class
method accepts an arrayref, hashref, or normal perl string in $value.</p>

<pre>
    $value = Apache2::Cookie-&gt;freeze([&quot;2+2&quot;, &quot;=4&quot;]);</pre>

<p>

</p>

<h2><a name="thaw">thaw</a></h2>

<pre>
    Apache2::Cookie-&gt;thaw($value)
    $cookie-&gt;thaw()</pre>

<p>This is the helper method (for <code>value</code>) responsible for decoding the
raw value of a cookie.  An optional argument $value may be used in
place of the cookie's raw value.  This method can also decode cookie
values created using CGI::Cookie or Apache2::Cookie 1.X.</p>

<pre>
    print $cookie-&gt;thaw;                    # prints &quot;bar&quot;
    @values = Apache2::Cookie-&gt;thaw($value); # ( &quot;2+2&quot;, &quot;=4&quot; )</pre>

<p>

</p>

<h2><a name="as_string">as_string</a></h2>

<pre>
    $cookie-&gt;as_string()</pre>

<p>Format the cookie object as a string.  The quote-operator for Apache2::Cookie
is overloaded to run this method whenever a cookie appears in quotes.</p>

<pre>
    ok &quot;$cookie&quot; eq $cookie-&gt;as_string;</pre>

<p>

</p>

<h2><a name="name">name</a></h2>

<pre>
    $cookie-&gt;name()</pre>

<p>Get the name of the cookie.</p>

<p>

</p>

<h2><a name="value">value</a></h2>

<pre>
    $cookie-&gt;value()</pre>

<p>Get the (unswizzled) value of the cookie:</p>

<pre>
    my $value = $cookie-&gt;value;
    my @values = $cookie-&gt;value;</pre>

<p>Note: if the cookie's value was created using a  <code>freeze</code> method,
one way to reconstitute the object is by subclassing
Apache2::Cookie with a package that provides the associated <code>thaw</code> sub:</p>

<pre>
    {
        package My::COOKIE;
        @ISA = 'Apache2::Cookie';
        sub thaw { my $val = shift-&gt;raw_value; $val =~ tr/a-z/A-Z/; $val }
    }</pre>

<pre>
    bless $cookie, &quot;My::COOKIE&quot;;</pre>

<pre>
    ok $cookie-&gt;value eq &quot;BAR&quot;;</pre>

<p>

</p>

<h2><a name="raw_value">raw_value</a></h2>

<pre>
    $cookie-&gt;raw_value()</pre>

<p>Gets the raw (opaque) value string as it appears in the incoming
&quot;Cookie&quot; header.</p>

<pre>
    ok $cookie-&gt;raw_value eq &quot;bar&quot;;</pre>

<p>

</p>

<h2><a name="bake">bake</a></h2>

<pre>
    $cookie-&gt;bake($r)</pre>

<p>Adds a <em>Set-Cookie</em> header to the outgoing headers table.</p>

<p>

</p>

<h2><a name="bake2">bake2</a></h2>

<pre>
    $cookie-&gt;bake2($r)</pre>

<p>Adds a <em>Set-Cookie2</em> header to the outgoing headers table.</p>

<p>

</p>

<h2><a name="domain">domain</a></h2>

<pre>
    $cookie-&gt;domain()
    $cookie-&gt;domain($set)</pre>

<p>Get or set the domain for the cookie:</p>

<pre>
    $domain = $cookie-&gt;domain;
    $cookie-&gt;domain(&quot;.cp.net&quot;);</pre>

<p>

</p>

<h2><a name="path">path</a></h2>

<pre>
    $cookie-&gt;path()
    $cookie-&gt;path($set)</pre>

<p>Get or set the path for the cookie:</p>

<pre>
    $path = $cookie-&gt;path;
    $cookie-&gt;path(&quot;/&quot;);</pre>

<p>

</p>

<h2><a name="version">version</a></h2>

<pre>
    $cookie-&gt;version()
    $cookie-&gt;version($set)</pre>

<p>Get or set the cookie version for this cookie.
Netscape spec cookies have version = 0;
RFC-compliant cookies have version = 1.</p>

<pre>
    ok $cookie-&gt;version == 0;
    $cookie-&gt;version(1);
    ok $cookie-&gt;version == 1;</pre>

<p>

</p>

<h2><a name="expires">expires</a></h2>

<pre>
    $cookie-&gt;expires()
    $cookie-&gt;expires($set)</pre>

<p>Get or set the future expire time for the cookie.  When
assigning, the new value ($set) should match /^\+?(\d+)([YMDhms]?)$/
$2 qualifies the number in $1 as representing &quot;Y&quot;ears, &quot;M&quot;onths,
&quot;D&quot;ays, &quot;h&quot;ours, &quot;m&quot;inutes, or &quot;s&quot;econds (if the qualifier is
omitted, the number is interpreted as representing seconds).
As a special case, $set = &quot;now&quot; is equivalent to $set = &quot;0&quot;.</p>

<pre>
    my $expires = $cookie-&gt;expires;
    $cookie-&gt;expires(&quot;+3h&quot;); # cookie is set to expire in 3 hours</pre>

<p>

</p>

<h2><a name="secure">secure</a></h2>

<pre>
    $cookie-&gt;secure()
    $cookie-&gt;secure($set)</pre>

<p>Get or set the secure flag for the cookie:</p>

<pre>
    $cookie-&gt;secure(1);
    $is_secure = $cookie-&gt;secure;
    $cookie-&gt;secure(0);</pre>

<p>

</p>

<h2><a name="httponly">httponly</a></h2>

<pre>
    $cookie-&gt;httponly()
    $cookie-&gt;httponly($set)</pre>

<p>Get or set the HttpOnly flag for the cookie:</p>

<pre>
    $cookie-&gt;httponly(1);
    $is_HttpOnly = $cookie-&gt;httponly;
    $cookie-&gt;httponly(0);</pre>

<p>

</p>

<h2><a name="httponly">httponly</a></h2>

<pre>
    $cookie-&gt;httponly()
    $cookie-&gt;httponly($set)</pre>

<p>Get or set the HttpOnly flag for the cookie:</p>

<pre>
    $cookie-&gt;httponly(1);
    $is_HttpOnly = $cookie-&gt;httponly;
    $cookie-&gt;httponly(0);</pre>

<p>

</p>

<h2><a name="comment">comment</a></h2>

<pre>
    $cookie-&gt;comment()
    $cookie-&gt;comment($set)</pre>

<p>Get or set the comment field of an RFC (Version &gt; 0) cookie.</p>

<pre>
    $cookie-&gt;comment(&quot;Never eat yellow snow&quot;);
    print $cookie-&gt;comment;</pre>

<p>

</p>

<h2><a name="commenturl">commentURL</a></h2>

<pre>
    $cookie-&gt;commentURL()
    $cookie-&gt;commentURL($set)</pre>

<p>Get or set the commentURL field of an RFC (Version &gt; 0) cookie.</p>

<pre>
    $cookie-&gt;commentURL(&quot;<a href="http://localhost/cookie.policy&quot">http://localhost/cookie.policy&quot</a>;);
    print $cookie-&gt;commentURL;</pre>

<p>

</p>

<h2><a name="fetch">fetch</a></h2>

<pre>
    Apache2::Cookie-&gt;fetch($r)</pre>

<p>Fetch and parse the incoming <em>Cookie</em> header:</p>

<pre>
    my $cookies = Apache2::Cookie-&gt;fetch($r); # APR::Request::Cookie::Table ref</pre>

<pre>
    It should be noted, that with perl 5.8+ Iterator magic, table is able
    to handle multiple cookies of the same name.</pre>

<pre>
    my %cookies = Apache2::Cookie-&gt;fetch($r);</pre>

<p>

</p>
<hr />

<h1><a name="porting_from_1_x">PORTING from 1.X</a></h1>

<p>Changes to the 1.X API:</p>

<ul>

<li>
<strong>
<a name="as" class="item"><code>Apache2::Cookie::fetch</code> now expects an <code>$r</code> object as (second)
        argument, although this isn't necessary in mod_perl 2 if
        <code>Apache2::RequestUtil</code> is loaded and 'PerlOptions +GlobalRequest'
        is in effect.</a>
</strong>



<li>
<strong>
<a name="apache2_cookie_parse_is_gone" class="item"><code>Apache2::Cookie::parse</code> is gone.</a>
</strong>



<li>
<strong>
<a name="apache2_cookie_new_no_longer_encodes_the_supplied_cookie_name" class="item"><code>Apache2::Cookie::new</code> no longer encodes the supplied cookie name.</a>
</strong>



<li>
<strong>
<a name="new" class="item"><code>Apache2::Cookie::new()</code> returns undef if -value is not specified
        or -value =&gt; undef.</a>
</strong>



<li>
<strong>
<a name="name" class="item"><code>name()</code> and <code>value()</code> no longer accept a &quot;set&quot; argument. In other words,
        neither a cookie's name, nor its value, may be modified.  A new cookie
        should be made instead.</a>
</strong>



</ul>


<p>

</p>
<hr />

<h1><a name="see_also">SEE ALSO</a></h1>

<p><a href="group__apreq__xs__request.html">the Apache2::Request manpage</a>, <a href="group__apreq__xs__apr__request__cookie.html">the APR::Request::Cookie manpage</a>,
<a href="group__apreq__xs__apr__request__error.html">the APR::Request::Error manpage</a>, CGI::Cookie(3)</p>

<p>

</p>
<hr />

<h1><a name="copyright">COPYRIGHT</a></h1>

<pre>
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the &quot;License&quot;); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at</pre>

<pre>
      <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a></pre>

<pre>
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.</pre>


 </div>
<div id="footer">
<p class="apache">
Copyright &copy; 2003-2006 <a href="http://www.apache.org">The Apache Software Foundation</a>.<br/>
See <a href="apreq_license.html">LICENSE</a>.</p>
<p class="menu">
<span style="color:#aaa">page generated by <a href="http://www.doxygen.org/"><code>doxygen</code></a>
version 1.5.6 on 25 Nov 2010</span>
</p>
</div>
</body>
</html>