diff --git a/bin/varnishd/builtin.vcl b/bin/varnishd/builtin.vcl index 6a0a5baf4bf..6b49d754e17 100644 --- a/bin/varnishd/builtin.vcl +++ b/bin/varnishd/builtin.vcl @@ -257,9 +257,18 @@ sub vcl_backend_error { } sub vcl_builtin_backend_error { + call vcl_refresh_error; call vcl_beresp_error; } +sub vcl_refresh_error { + if (beresp.was_304) { + unset bereq.http.If-Modified-Since; + unset bereq.http.If-None-Match; + return (retry(fetch)); + } +} + sub vcl_beresp_error { set beresp.http.Content-Type = "text/html; charset=utf-8"; set beresp.http.Retry-After = "5"; diff --git a/bin/varnishtest/tests/c00129.vtc b/bin/varnishtest/tests/c00129.vtc index 38c3bc69252..888f5e39de2 100644 --- a/bin/varnishtest/tests/c00129.vtc +++ b/bin/varnishtest/tests/c00129.vtc @@ -29,13 +29,6 @@ varnish v1 -vcl+backend { set beresp.grace = 0s; set beresp.keep = 10s; } - sub vcl_backend_error { - if (beresp.was_304) { - unset bereq.http.If-Modified-Since; - unset bereq.http.If-None-Match; - return (retry(fetch)); - } - } sub vcl_deliver { set resp.http.obj-hits = obj.hits; } diff --git a/doc/sphinx/reference/vcl_step.rst b/doc/sphinx/reference/vcl_step.rst index ee07f616923..fe1b46830ea 100644 --- a/doc/sphinx/reference/vcl_step.rst +++ b/doc/sphinx/reference/vcl_step.rst @@ -392,6 +392,10 @@ circumstances, be cautious with putting private information there. If you really must, then you need to explicitly set ``beresp.ttl`` to zero in ``vcl_backend_error``. +If a conditional fetch failed to process a 304 response and transitioned +to ``vcl_backend_error``, the backend request is retried for a regular +fetch within the same transaction. + The `vcl_backend_error` subroutine may terminate with calling ``return()`` with one of the following keywords: diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst index 4697211648b..9bebb64be40 100644 --- a/doc/sphinx/reference/vcl_var.rst +++ b/doc/sphinx/reference/vcl_var.rst @@ -1378,7 +1378,8 @@ beresp.was_304 When ``true`` this indicates that we got a 304 response to our conditional fetch from the backend and turned - that into ``beresp.status = 200`` + that into ``beresp.status = 200``, unless the refresh + attempt failed. obj