emptygif
語言: 繁體中文

所有語言和框架

Varnish (VCL synthetic) VCL

適用於 Varnish (VCL synthetic) 的 VCL 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

Varnish (VCL synthetic) VCL

檔案
default.vcl
執行
varnishd -f /etc/varnish/default.vcl -a :8080
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

官方網站: Varnish (VCL synthetic)