<div dir="ltr"><div class="gmail_quote"><div dir="ltr">Hi,<div><br></div><div>I'm running Varnish in front of a back end that has to do some work to determine whether a request should receive a 404 response. However, it can cheaply determine whether a previous 404 is still valid.</div><div><br></div><div>I see Varnish issuing conditional requests for cached 200 responses, but I haven't managed to achieve the same for cached 404 responses.</div><div><br></div><div>Here's my sample VCL:</div><div><br></div><div><br></div><div><font face="monospace">vcl 4.1;<br><br>backend default {<br> .host = "localhost";<br> .port = "8081";<br>}<br><br>sub vcl_backend_response {<br> set beresp.keep = 5m;<br>}<br></font></div><div><br></div><div><br></div><div>I'm testing with canned responses on port 8081 For the working 200 case, I return:</div><div><br></div><div><br></div><div><font face="monospace">HTTP/1.1 200 OK<br>cache-control: max-age=5<br>etag: "foo"<br>content-length: 13<br>connection: close<br><br>Hello, World!<br></font></div><div><br></div><div><br></div><div>When I make requests to Varnish, I see, as expected, a first request to the back end, followed by five seconds of nothing to the back end, because Varnish is responding with its cached copy, followed by a conditional request to the back end:</div><div><br></div><div><br></div><div><font face="monospace">GET / HTTP/1.1<br>Host: localhost:8080<br>User-Agent: curl/7.68.0<br>Accept: */*<br>X-Forwarded-For: 127.0.0.1<br>Accept-Encoding: gzip<br>X-Varnish: 3<br><br>GET / HTTP/1.1<br>Host: localhost:8080<br>User-Agent: curl/7.68.0<br>Accept: */*<br>X-Forwarded-For: 127.0.0.1<br>Accept-Encoding: gzip<br>If-None-Match: "foo"<br>X-Varnish: 32773<br></font></div><div><br></div><div><br></div><div>For the failing 404 case, my canned back end responds:</div><div><br></div><div><br></div><div><font face="monospace">HTTP/1.1 404 Not Found<br>cache-control: max-age=5<br>etag: "foo"<br>content-length: 13<br>connection: close<br><br>Hello, World!<br></font></div><div><br></div><div><br></div><div>Now when I make requests to Varnish, I get a cached response for five seconds as before, but when the response goes stale, rather than issuing a conditional request to revalidate it, Varnish is issuing unconditional requests:<br></div><div><br></div><div><br></div><div><font face="monospace">GET / HTTP/1.1<br>Host: localhost:8080<br>User-Agent: curl/7.68.0<br>Accept: */*<br>X-Forwarded-For: 127.0.0.1<br>Accept-Encoding: gzip<br>X-Varnish: 3<br><br>GET / HTTP/1.1<br>Host: localhost:8080<br>User-Agent: curl/7.68.0<br>Accept: */*<br>X-Forwarded-For: 127.0.0.1<br>Accept-Encoding: gzip<br>X-Varnish: 32771<br></font></div><div><br></div><div><br></div><div>Is that something I can adjust with configuration? If it's relevant, I'm running:</div><div><br></div><div>Debug: Version: varnish-6.2.1 revision 9f8588e4ab785244e06c3446fe09bf9db5dd8753<br>Debug: Platform: Linux,5.4.0-153-generic,x86_64,-jnone,-sdefault,-sdefault,-hcritbit<br></div><div><br></div><div>Incidentally, 200 responses with content-length 0 also seem to exhibit this behaviour.</div><div><br></div><div>Thanks in advance,</div><div><br></div><div>Mark</div><div><br></div><div><br></div><div><br></div><div><br></div></div>
</div></div>