Varnish (VCL synthetic) VCL
一个用于 Varnish (VCL synthetic) 的 VCL 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。
Varnish (VCL synthetic) VCL
vcl 4.1;
import blob;
backend default none; # or your real backend
sub vcl_recv {
if (regsub(req.url, "\?.*$", "") == "/pixel.gif") {
return (synth(200, "OK"));
}
}
sub vcl_synth {
if (resp.status == 200 && regsub(req.url, "\?.*$", "") == "/pixel.gif") {
set resp.http.Content-Type = "image/gif";
set resp.http.Cache-Control = "no-store";
set resp.body = blob.decode(BASE64, encoded="R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
return (deliver);
}
}
我们运行了此代码片段,并比对了它返回的字节。
验证
curl -sI http://localhost:8080/pixel.gif