Add custom error pages config to VarnishConfig
Idea: add an error-pages
field to VarnishConfig, which is a non-empty array of objects like this:
error-pages:
- status: 400
status-max: 403
url: /error/4xx.html
host: error.svc.com
- status: 404
url: /humorous404
- status: 405
status-max: 499
url: /error/4xx.html
host: error.svc.com
- status: 500
status-max: 599
url: /error/5xx.html
host: error.svc.com
-
status
andurl
are required,status-max
andhost
are optional. -
status
andstatus-max
restricted to [400,599],status-max
>status
- If only
status
is set, the config is for that response code only. Ifstatus-max
is also set, then the config is for the range[status,status-max]
inclusive.- Validation should check that ranges do not overlap.
- The config sets a URL and possibly Host for an error page. These can then be routed to backend Services with the usual means of Ingress.
For VCL code generation, use VK8S-Error-Restart-*
request headers to drive restarts to custom error pages:
-
In
vcl_recv
:- If
restarts > 0 && req.http.VK8S-Error-Restart-URL
:set req.url = req.http.VK8S-Error-Restart-URL
- If
req.http.VK8S-Error-Restart-Host
:set req.http.Host = req.http.VK8S-Error-Restart-Host
- This all happens before evaluating Ingress rules, so setting URL and Host may have the effect of choosing a backend Service for error pages.
- If
-
In
vcl_deliver
:- If the
req.http.VK8S-Error-Restart-*
headers exist:set resp.status = std.integer(req.http.VK8S-Error-Restart-Status, 503)
set resp.reason = req.http.VK8S-Error-Restart-Reason
return(deliver)
- else if
resp.status
falls in a range for custom error pagesset req.http.VK8S-Error-Restart-Status = resp.status
set req.http.VK8S-Error-Restart-Reason = resp.reason
-
set req.http.VK8S-Error-Restart-URL = {{errorURL}}
, whereerrorURL
is the URL configured for the error status - If a
Host
was configured for the error status:set req.http.VK8S-Error-Restart-Host = {{Host}}
return(restart)
- If the