File: group__apreq__xs__cookie.html

package info (click to toggle)
libapreq2 2.17-3~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 5,108 kB
  • sloc: ansic: 8,263; perl: 5,451; sh: 4,627; cpp: 380; makefile: 270; javascript: 186
file content (375 lines) | stat: -rw-r--r-- 14,832 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<html>
<head>
  <link rel="stylesheet" type="text/css" href="dox.css" />
  <title>libapreq2-2.17: 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.9.1 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Apache2::Cookie<div class="ingroups"><a class="el" href="group__apreq__lang.html">Language Bindings</a> &raquo; <a class="el" href="group__apreq__xs.html">Perl</a></div></div>  </div>
</div><!--header-->
<div class="contents">




<ul id="index">
  <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>
    <ul>
      <li><a href="#new">new</a></li>
      <li><a href="#cookies">cookies</a></li>
      <li><a href="#status">status</a></li>
    </ul>
  </li>
  <li><a href="#Apache2::Cookie">Apache2::Cookie</a>
    <ul>
      <li><a href="#new1">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="#comment">comment</a></li>
      <li><a href="#commentURL">commentURL</a></li>
      <li><a href="#fetch">fetch</a></li>
    </ul>
  </li>
  <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>

<h1 id="NAME">NAME</h1>

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

<h1 id="SYNOPSIS">SYNOPSIS</h1>

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

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

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

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

<h1 id="DESCRIPTION">DESCRIPTION</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">&quot;PORTING from 1.X&quot;</a> section below for known issues).</p>

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

<h1 id="Apache2::Cookie::Jar">Apache2::Cookie::Jar</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>

<h2 id="new">new</h2>

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

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

<h2 id="cookies">cookies</h2>

<pre><code>$jar-&gt;cookies()
$jar-&gt;cookies($key)</code></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&#39;s internal <i>cookies</i> 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&#39;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><code>$c = Apache2::Cookie-&gt;new($r, name =&gt; &quot;foo&quot;, value =&gt; 3);
$j-&gt;cookies-&gt;add($c);

$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</code></pre>

<h2 id="status">status</h2>

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

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

<h1 id="Apache2::Cookie">Apache2::Cookie</h1>

<h2 id="new1">new</h2>

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

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

<pre><code>$cookie = Apache2::Cookie-&gt;new($r,
                         -name    =&gt;  &#39;foo&#39;,
                         -value   =&gt;  &#39;bar&#39;,
                         -expires =&gt;  &#39;+3M&#39;,
                         -domain  =&gt;  &#39;.capricorn.com&#39;,
                         -path    =&gt;  &#39;/cgi-bin/database&#39;,
                         -secure  =&gt;  1
                        );</code></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&#39;s raw value.</p>

<h2 id="freeze">freeze</h2>

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

<p>Helper function (for <code>new</code>) that serializes a new cookie&#39;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><code>$value = Apache2::Cookie-&gt;freeze([&quot;2+2&quot;, &quot;=4&quot;]);</code></pre>

<h2 id="thaw">thaw</h2>

<pre><code>Apache2::Cookie-&gt;thaw($value)
$cookie-&gt;thaw()</code></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&#39;s raw value. This method can also decode cookie values created using CGI::Cookie or Apache2::Cookie 1.X.</p>

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

<h2 id="as_string">as_string</h2>

<pre><code>$cookie-&gt;as_string()</code></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><code>ok &quot;$cookie&quot; eq $cookie-&gt;as_string;</code></pre>

<h2 id="name">name</h2>

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

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

<h2 id="value">value</h2>

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

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

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

<p>Note: if the cookie&#39;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><code>{
    package My::COOKIE;
    @ISA = &#39;Apache2::Cookie&#39;;
    sub thaw { my $val = shift-&gt;raw_value; $val =~ tr/a-z/A-Z/; $val }
}

bless $cookie, &quot;My::COOKIE&quot;;

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

<h2 id="raw_value">raw_value</h2>

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

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

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

<h2 id="bake">bake</h2>

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

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

<h2 id="bake2">bake2</h2>

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

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

<h2 id="domain">domain</h2>

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

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

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

<h2 id="path">path</h2>

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

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

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

<h2 id="version">version</h2>

<pre><code>$cookie-&gt;version()
$cookie-&gt;version($set)</code></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><code>ok $cookie-&gt;version == 0;
$cookie-&gt;version(1);
ok $cookie-&gt;version == 1;</code></pre>

<h2 id="expires">expires</h2>

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

<h2 id="secure">secure</h2>

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

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

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

<h2 id="httponly">httponly</h2>

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

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

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

<h2 id="comment">comment</h2>

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

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

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

<h2 id="commentURL">commentURL</h2>

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

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

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

<h2 id="fetch">fetch</h2>

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

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

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

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

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

<h1 id="PORTING-from-1.X">PORTING from 1.X</h1>

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

<ul>

<li><p><code>Apache2::Cookie::fetch</code> now expects an <code>$r</code> object as (second) argument, although this isn&#39;t necessary in mod_perl 2 if <code>Apache2::RequestUtil</code> is loaded and &#39;PerlOptions +GlobalRequest&#39; is in effect.</p>

</li>
<li><p><code>Apache2::Cookie::parse</code> is gone.</p>

</li>
<li><p><code>Apache2::Cookie::new</code> no longer encodes the supplied cookie name.</p>

</li>
<li><p><code>Apache2::Cookie::new()</code> returns undef if -value is not specified or -value =&gt; undef.</p>

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

</li>
</ul>

<h1 id="SEE-ALSO">SEE ALSO</h1>

<p><a>Apache2::Request</a>, <a>APR::Request::Cookie</a>, <a>APR::Request::Error</a>, CGI::Cookie(3)</p>

<h1 id="COPYRIGHT">COPYRIGHT</h1>

<pre><code>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

    http://www.apache.org/licenses/LICENSE-2.0

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.</code></pre>


 </div><!-- contents -->
<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.9.1 on Thu Aug 18 2022</span>
</p>
</div>
</body>
</html>