-
Notifications
You must be signed in to change notification settings - Fork 86
/
vmod_accept.vcc
56 lines (39 loc) · 1.45 KB
/
vmod_accept.vcc
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
#
# Copyright (c) 2016 Guillaume Quintard
#
# Author: Guillaume Quintard <[email protected]>
#
# (vmodtool requires this format.)
#
$Module accept 3 Accept VMOD
DESCRIPTION
===========
accept allows you to sanitize the Accept* headers (mainly Accept,
Accept-Charset and Accept-Encoding) by specify one fallback string, and then
adding valid values::
sub vcl_init {
new rule = accept.rule("text/plain");
rule.add("text/html");
rule.add("application/json");
}
You can then use the ``rule`` object to filter the headers. The following line
will set the accept header to "text/html" or "application/json" if any of them
is found in the original header, and will set it to "text/plain" if neither is
found::
sub vcl_recv {
set req.http.Accept = rule.filter(req.http.Accept);
}
accept will ignore any parameter found and will just return the first choice
found. More info here: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
API
===
$Object rule(STRING string)
Create a rule object, setting the fallback string.
$Method VOID .add(STRING string)
Add ``string`` to the list of valid choices.
$Method VOID .remove(STRING string)
Remove ``string`` to the list of valid choices.
$Method STRING .filter(STRING string)
Parse string and try to find a valid choice. The first one found is returned
(they are tested in the same order they were added), otherwise, the fallback
string is returned.