-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.vcl
141 lines (108 loc) · 3.04 KB
/
main.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
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
sub vcl_recv {
if (req.http.Fastly-FF) {
set req.max_stale_while_revalidate = 0s;
}
#FASTLY recv
###########################################
# LB WORKSHOP - DO STUFF HERE
###########################################
# Workshop 1 default backend.
set req.backend = cloudpool;
###########################################
# END LB WORKSHOP
###########################################
if (req.request != "HEAD" && req.request != "GET" && req.request != "FASTLYPURGE") {
return(pass);
}
# PASSING ALL TRAFFIC SO WE CAN SEE THE WORKSHOP IN ACTION
return(pass);
}
sub vcl_fetch {
/* handle 5XX (or any other unwanted status code) */
if (beresp.status >= 500 && beresp.status < 600) {
/* deliver stale if the object is available */
if (stale.exists) {
return(deliver_stale);
}
if (req.restarts < 1 && (req.request == "GET" || req.request == "HEAD")) {
restart;
}
/* else go to vcl_error to deliver a synthetic */
error 503;
}
/* set stale_if_error and stale_while_revalidate (customize these values) */
set beresp.stale_if_error = 86400s;
set beresp.stale_while_revalidate = 60s;
#FASTLY fetch
if ((beresp.status == 500 || beresp.status == 503) && req.restarts < 1 && (req.request == "GET" || req.request == "HEAD")) {
restart;
}
if (req.restarts > 0) {
set beresp.http.Fastly-Restarts = req.restarts;
}
if (beresp.http.Set-Cookie) {
set req.http.Fastly-Cachetype = "SETCOOKIE";
return(pass);
}
if (beresp.http.Cache-Control ~ "private") {
set req.http.Fastly-Cachetype = "PRIVATE";
return(pass);
}
/* this code will never be run, commented out for clarity */
/* if (beresp.status == 500 || beresp.status == 503) {
set req.http.Fastly-Cachetype = "ERROR";
set beresp.ttl = 1s;
set beresp.grace = 5s;
return(deliver);
} */
if (beresp.http.Expires || beresp.http.Surrogate-Control ~ "max-age" || beresp.http.Cache-Control ~ "(s-maxage|max-age)") {
# keep the ttl here
} else {
# apply the default ttl
set beresp.ttl = 3600s;
}
return(deliver);
}
sub vcl_hit {
#FASTLY hit
if (!obj.cacheable) {
return(pass);
}
return(deliver);
}
sub vcl_miss {
#FASTLY miss
return(fetch);
}
sub vcl_deliver {
if (resp.status >= 500 && resp.status < 600) {
/* restart if the stale object is available */
if (stale.exists) {
restart;
}
}
# Ensure browsers don't cache
set resp.http.Cache-Control = "no-cache, no-store, must-revalidate";
#FASTLY deliver
return(deliver);
}
sub vcl_error {
#FASTLY error
/* handle 503s */
if (obj.status >= 500 && obj.status < 600) {
/* deliver stale object if it is available */
if (stale.exists) {
return(deliver_stale);
}
/* otherwise, return a synthetic */
/* include your HTML response here */
synthetic {"<!DOCTYPE html><html>Replace this text with the error page you would like to serve to clients if your origin is offline.</html>"};
return(deliver);
}
}
sub vcl_pass {
#FASTLY pass
}
sub vcl_log {
#FASTLY log
}