@@ -57,14 +57,11 @@ Symfony adds automatically:
5757..code-block ::text
5858
5959 sub vcl_fetch {
60- /*
61- Check for ESI acknowledgement
62- and remove Surrogate-Control header
63- */
60+ // Check for ESI acknowledgement and remove Surrogate-Control header
6461 if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
6562 unset beresp.http.Surrogate-Control;
6663
67- // For Varnish >= 3.0
64+ // For Varnish >= 3.0, < 4.0
6865 set beresp.do_esi = true;
6966 // For Varnish < 3.0
7067 // esi;
@@ -79,6 +76,30 @@ Symfony adds automatically:
7976 }
8077 }
8178
79+ /**
80+ * For Varnish >= 4.0
81+ * https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html#req-not-available-in-vcl-backend-response
82+ */
83+ sub vcl_backend_response {
84+ // Check for ESI acknowledgement and remove Surrogate-Control header
85+ if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
86+ unset beresp.http.Surrogate-Control;
87+
88+ set beresp.do_esi = true;
89+ }
90+ // By default Varnish ignores Cache-Control: nocache
91+ // (https://www.varnish-cache.org/docs/3.0/tutorial/increasing_your_hitrate.html#cache-control),
92+ // so in order avoid caching it has to be done explicitly
93+ if (beresp.http.Pragma ~ "no-cache" ||
94+ beresp.http.Cache-Control ~ "no-cache" ||
95+ beresp.http.Cache-Control ~ "private") {
96+ // https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html#hit-for-pass-objects-are-created-using-beresp-uncacheable
97+ set beresp.uncacheable = true;
98+ set beresp.ttl = 120s;
99+ return (deliver);
100+ }
101+ }
102+
82103 ..caution ::
83104
84105 Compression with ESI was not supported in Varnish until version 3.0