有没有办法强制 Varnish 读取 403 响应中的 Cache-Control header?

Is there a way to force Varnish to read the Cache-Control header on 403 responses?

从代码看来,由于 403 不是白名单状态,因此 Cache-Control header 被忽略:

switch (http_GetStatus(hp)) {
    default:
        expp->ttl = -1.;

https://github.com/varnishcache/varnish-cache/blob/4.0/bin/varnishd/cache/cache_rfc2616.c#L112-L114

这是我能想到的最好的:

sub vcl_backend_response {
  if (beresp.status == 403) {
    set beresp.http.X-Status = beresp.status;
    set beresp.status = 200;
  }
}

sub vcl_deliver {
    if (resp.http.X-Status) {
      set resp.status = std.integer(resp.http.X-Status, 403);
      unset resp.http.X-Status;
    }
}

虽然这可以正确设置和取消设置状态,但每个请求都是一个缓存 MISS

#2018

varnish 默认不缓存 403 响应。

"You can cache other status codes than the ones listed above, but you have to set the beresp.ttl to a positive value in vcl_backend_response. "

http://book.varnish-software.com/4.0/chapters/VCL_Basics.html#the-initial-value-of-beresp-ttl