File: vmod_cookie.3

package info (click to toggle)
varnish 6.5.1-1%2Bdeb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 19,720 kB
  • sloc: ansic: 95,295; javascript: 9,411; sh: 4,673; python: 2,157; makefile: 1,353; awk: 114; ruby: 34
file content (391 lines) | stat: -rw-r--r-- 7,777 bytes parent folder | download
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
.\" Man page generated from reStructuredText.
.
.TH VMOD_COOKIE 3 "" "" ""
.SH NAME
vmod_cookie \- Varnish Cookie Module
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.\" 
.
.\" NB:  This file is machine generated, DO NOT EDIT!
.
.\" 
.
.\" Edit ./vmod_cookie.vcc and run make instead
.
.\" 
.
.SH SYNOPSIS
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
import cookie [as name] [from "path"]

VOID clean()

VOID delete(STRING cookiename)

VOID filter(STRING filterstring)

VOID filter_re(STRING expression)

VOID keep(STRING filterstring)

VOID keep_re(STRING expression)

STRING format_rfc1123(TIME now, DURATION timedelta)

STRING get(STRING cookiename)

STRING get_re(STRING expression)

STRING get_string()

BOOL isset(STRING cookiename)

VOID parse(STRING cookieheader)

VOID set(STRING cookiename, STRING value)
.ft P
.fi
.UNINDENT
.UNINDENT
.SH DESCRIPTION
.sp
Handle HTTP cookies more easily in Varnish VCL.
.sp
Parses a cookie header into an internal data store, where per\-cookie
get/set/delete functions are available. A keep() function removes all
but a set comma\-separated list of cookies. A filter() function removes a comma\-
separated list of cookies.
.sp
Regular expressions can be used for either selecting cookies, deleting matching
cookies and deleting non\-matching cookie names.
.sp
A convenience function for formatting the Set\-Cookie Expires date field
is also included.
.sp
The state loaded with cookie.parse() has a lifetime of the current request
or backend request context. To pass variables to the backend request, store
the contents as fake bereq headers.
.sp
Filtering example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
import cookie;

sub vcl_recv {
    if (req.http.cookie) {
        cookie.parse(req.http.cookie);
        # Either delete the ones you want to get rid of:
        cookie.delete("cookie2");
        # or delete all but a few:
        cookie.keep("SESSIONID,PHPSESSID");

        # Store it back into req so it will be passed to the backend.
        set req.http.cookie = cookie.get_string();

        # If empty, unset so the builtin VCL can consider it for caching.
        if (req.http.cookie == "") {
            unset req.http.cookie;
        }
    }
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS VOID clean()
.sp
Clean up previously parsed cookies. It is not necessary to run clean()
in normal operations.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_recv {
    cookie.clean();
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS VOID delete(STRING cookiename)
.sp
Delete \fBcookiename\fP from internal vmod storage if it exists.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_recv {
    cookie.parse("cookie1: value1; cookie2: value2;");
    cookie.delete("cookie2");
    # get_string() will now yield "cookie1: value1";
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS VOID filter(STRING filterstring)
.sp
Delete all cookies from internal vmod storage that are in the
comma\-separated argument cookienames.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_recv {
    cookie.parse("cookie1: value1; cookie2: value2; cookie3: value3");
    cookie.filter("cookie1,cookie2");
    # get_string() will now yield
    # "cookie3: value3";
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS VOID filter_re(STRING expression)
.sp
Delete all cookies from internal vmod storage that matches the
regular expression \fBexpression\fP\&.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_recv {
    cookie.parse("cookie1: value1; cookie2: value2; cookie3: value3");
    cookie.filter_re("^cookie[12]$");
    # get_string() will now yield
    # "cookie3: value3";
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS VOID keep(STRING filterstring)
.sp
Delete all cookies from internal vmod storage that is not in the
comma\-separated argument cookienames.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_recv {
    cookie.parse("cookie1: value1; cookie2: value2; cookie3: value3");
    cookie.keep("cookie1,cookie2");
    # get_string() will now yield
    # "cookie1: value1; cookie2: value2;";
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS VOID keep_re(STRING expression)
.sp
Delete all cookies from internal vmod storage that does not match
expression \fBexpression\fP\&.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_recv {
    cookie.parse("cookie1: value1; cookie2: value2; cookie3: value3");
    cookie.keep_re("^cookie1,cookie2");
    # get_string() will now yield
    # "cookie1: value1; cookie2: value2;";
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS STRING format_rfc1123(TIME now, DURATION timedelta)
.sp
Get a RFC1123 formatted date string suitable for inclusion in a
Set\-Cookie response header.
.sp
Care should be taken if the response has multiple Set\-Cookie headers.
In that case the header vmod should be used.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_deliver {
    # Set a userid cookie on the client that lives for 5 minutes.
    set resp.http.Set\-Cookie = "userid=" + req.http.userid +
        "; Expires=" + cookie.format_rfc1123(now, 5m) + "; httpOnly";
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS STRING get(STRING cookiename)
.sp
Get the value of \fBcookiename\fP, as stored in internal vmod storage. If
\fBcookiename\fP does not exist an empty string is returned.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
import std;
sub vcl_recv {
    cookie.parse("cookie1: value1; cookie2: value2;");
    std.log("cookie1 value is: " + cookie.get("cookie1"));
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS STRING get_re(STRING expression)
.sp
Get the value of the first cookie in internal vmod storage that matches
regular expression \fBexpression\fP\&. If nothing matches, an empty string
is returned.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
import std;
sub vcl_recv {
    cookie.parse("cookie1: value1; cookie2: value2;");
    std.log("cookie1 value is: " + cookie.get_re("^cookie1$"));
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS STRING get_string()
.sp
Get a Cookie string value with all cookies in internal vmod storage. Does
not modify internal storage.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_recv {
    cookie.parse(req.http.cookie);
    cookie.keep("SESSIONID,PHPSESSID");
    set req.http.cookie = cookie.get_string();
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS BOOL isset(STRING cookiename)
.sp
Check if \fBcookiename\fP is set in the internal vmod storage.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
import std;
sub vcl_recv {
    cookie.parse("cookie1: value1; cookie2: value2;");
    if (cookie.isset("cookie2")) {
        std.log("cookie2 is set.");
    }
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS VOID parse(STRING cookieheader)
.sp
Parse the cookie string in \fBcookieheader\fP\&. If state already exists,
\fBclean()\fP will be run first.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_recv {
    cookie.parse(req.http.Cookie);
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS VOID set(STRING cookiename, STRING value)
.sp
Set the internal vmod storage for \fBcookiename\fP to \fBvalue\fP\&.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sub vcl_recv {
    cookie.set("cookie1", "value1");
    std.log("cookie1 value is: " + cookie.get("cookie1"));
}
.ft P
.fi
.UNINDENT
.UNINDENT
.\" Generated by docutils manpage writer.
.