Skip to content

Commit

Permalink
builtin: Retry failed 304s by default
Browse files Browse the repository at this point in the history
Named after vcl_backend_refresh from #3994.
  • Loading branch information
dridi committed Mar 19, 2024
1 parent bdaec65 commit a0b6a7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions bin/varnishd/builtin.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,16 @@ 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) {
return (retry);
}
}

sub vcl_beresp_error {
set beresp.http.Content-Type = "text/html; charset=utf-8";
set beresp.http.Retry-After = "5";
Expand Down
4 changes: 4 additions & 0 deletions doc/sphinx/reference/vcl_step.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 transaction is retried as a regular
fetch.

The `vcl_backend_error` subroutine may terminate with calling ``return()``
with one of the following keywords:

Expand Down
3 changes: 2 additions & 1 deletion doc/sphinx/reference/vcl_var.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0b6a7e

Please sign in to comment.