1VMOD_ACCEPT(3) VMOD_ACCEPT(3)
2
3
4
6 vmod_accept - Accept VMOD
7
9 import accept [as name] [from "path"]
10
11 new xrule = accept.rule(STRING string)
12
13 VOID xrule.add(STRING string)
14
15 VOID xrule.remove(STRING string)
16
17 STRING xrule.filter(STRING string)
18
20 accept allows you to sanitize the Accept* headers (mainly Accept, Ac‐
21 cept-Charset and Accept-Encoding) by specify one fallback string, and
22 then adding valid values:
23
24 sub vcl_init {
25 new rule = accept.rule("text/plain");
26 rule.add("text/html");
27 rule.add("application/json");
28 }
29
30 You can then use the rule object to filter the headers. The following
31 line will set the accept header to "text/html" or "application/json" if
32 any of them is found in the original header, and will set it to
33 "text/plain" if neither is found:
34
35 sub vcl_recv {
36 set req.http.Accept = rule.filter(req.http.Accept);
37 }
38
39 accept will ignore any parameter found and will just return the first
40 choice found. More info here:
41 https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
42
44 new xrule = accept.rule(STRING string)
45 Create a rule object, setting the fallback string.
46
47 VOID xrule.add(STRING string)
48 Add string to the list of valid choices.
49
50 VOID xrule.remove(STRING string)
51 Remove string to the list of valid choices.
52
53 STRING xrule.filter(STRING string)
54 Parse string and try to find a valid choice. The first one found is re‐
55 turned (they are tested in the same order they were added), otherwise,
56 the fallback string is returned.
57
59 Copyright (c) 2016 Guillaume Quintard
60
61 Author: Guillaume Quintard <guillaume.quintard@gmail.com>
62
63 (vmodtool requires this format.)
64
65
66
67
68 VMOD_ACCEPT(3)