is there a way to change what is delivered to the client between the backend response and the delivery?
i'm trying to figure out a way to continue to serve graced objects if the backend returns a 4xx or 5xx response (which don't get cached). the backend probe hits a static page, which will keep the backend healthy as long as the webserver on it is running, but dynamic pages will return errors if they run into problems.
currently, graced objects will continue to be served if the probe fails (e.g. i shut down the webserver completely on the backend). but if i just break the site itself, I see the first request returns the cached object and initiates a new fetch from the backend, and then the following requests pass through the non-cacheable error (404 in this case).
I can't seem to find a way for varnish to try to fetch from the backend, get an error response, and serve the graced object instead of the error, unless the backend is recognized as completely unhealthy. am i missing a step?
You can do that adding some VCL to your configuration. Please, check my answer to a similar question: https://stackoverflow.com/a/32970571/1806102.
The idea is (1) abandon the request during
vcl_backend_response
; (2) restart the request duringvcl_synth
; (3) set a always-sick backend duringvcl_recv
; and (4) deliver grace content duringvcl_hit
if the backend is sick.