-
Notifications
You must be signed in to change notification settings - Fork 8
/
example.vcl
85 lines (66 loc) · 1.96 KB
/
example.vcl
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
# VCL examples.
# Tip: read up the tests for more complex use-cases
# len_req_body()
# It can be called only from vcl_recv.
sub vcl_recv {
std.cache_req_body(110B);
set req.http.x-len = bodyaccess.len_req_body();
}
sub vcl_deliver {
set resp.http.x-len = req.http.x-len;
}
/------------------------------------------------------------------------------/
# hash_req_body()
# It can be called only form vcl_hash.
sub vcl_recv {
std.cache_req_body(110B);
return (hash);
}
sub vcl_hash {
bodyaccess.hash_req_body();
return (lookup);
}
/------------------------------------------------------------------------------/
# rematch_req_body(STRING re)
# It can be called only form vcl_recv.
sub vcl_recv {
std.cache_req_body(10KB);
set req.http.x-re = bodyaccess.rematch_req_body("Regex");
}
sub vcl_deliver {
set resp.http.x-re = req.http.x-re;
}
/------------------------------------------------------------------------------/
# forcing Varnish to use the same request method also for backend request.
# Note without this part of VCL every request method will be converted
# to GET on backend side.
sub vcl_recv {
if (req.method == "POST") {
set req.http.x-method = req.method;
}
}
sub vcl_backend_fetch {
set bereq.method = bereq.http.x-method;
}
/------------------------------------------------------------------------------/
# skeleton VCL using all the functions from this Vmod.
sub vcl_recv {
if (req.method == "POST") {
set req.http.x-method = req.method;
std.cache_req_body(110KB);
set req.http.x-len = bodyaccess.len_req_body();
set req.http.x-re = bodyaccess.rematch_req_body("Regex"$
}
return(hash);
}
sub vcl_hash {
bodyaccess.hash_req_body();
return (lookup);
}
sub vcl_backend_fetch {
set bereq.method = bereq.http.x-method;
}
sub vcl_deliver {
set resp.http.x-len = req.http.x-len;
set resp.http.x-re = req.http.x-re;
}