[Fixed]Issues with ESI
Hi there,
I’m struggling with ESI as it doesn’t want to work.
This is my VCL.
sub vcl_recv {
if (req.http.Fastly-FF) {
set req.esi = false;
}
#FASTLY recv
if (req.request != “HEAD” && req.request != “GET” && req.request != “FASTLYPURGE”) {
return(pass);
}
return(lookup);
}
sub vcl_fetch {
if (req.url.ext == "html") {
esi;
}
if (req.url == "/2017/05/23/apple-server-most-powerful-rack-optimized-server") {
esi;
}
if (req.url == "/test.html") {
esi;
}
if (req.url == "/test") {
esi;
}
if (req.url == "/2017/05/23/apple-server-most-powerful-rack-optimized-server/") {
esi;
}
#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);
}
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 {
#FASTLY deliver
return(deliver);
}
sub vcl_error {
#FASTLY error
}
sub vcl_pass {
#FASTLY pass
}
sub vcl_log {
#FASTLY log
}
I’m seeing, every time, the esi tag into the html, not the code.
I tested this one too: https://github.com/andriantoniades/Using-ESI-with-Boilerplate-VCL
Regards,
Astin
-
Found the problem. The encoding should be disabled (it is enabled by default). In order to do that: sub vcl_miss { unset bereq.http.accept-encoding; }
Also, to enable ESI only for html content type I use:
sub vcl_fetch { if (beresp.http.content-type ~ "text/html*") { esi; } }
Hope this will help others.
Regards, Astin
Please sign in to leave a comment.
Comments
1 comment