Support rewriting status codes in error page middleware
This commit is contained in:
parent
f0849e8ee6
commit
fa76ed57d3
18 changed files with 195 additions and 8 deletions
|
@ -9,6 +9,8 @@ spec:
|
|||
status:
|
||||
- "404"
|
||||
- "500"
|
||||
statusRewrites:
|
||||
404: 200
|
||||
query: query
|
||||
service:
|
||||
name: whoami
|
||||
|
|
|
@ -737,8 +737,9 @@ func (p *Provider) createErrorPageMiddleware(client Client, namespace string, er
|
|||
}
|
||||
|
||||
errorPageMiddleware := &dynamic.ErrorPage{
|
||||
Status: errorPage.Status,
|
||||
Query: errorPage.Query,
|
||||
Status: errorPage.Status,
|
||||
StatusRewrites: errorPage.StatusRewrites,
|
||||
Query: errorPage.Query,
|
||||
}
|
||||
|
||||
cb := configBuilder{
|
||||
|
|
|
@ -4160,7 +4160,10 @@ func TestLoadIngressRoutes(t *testing.T) {
|
|||
Middlewares: map[string]*dynamic.Middleware{
|
||||
"default-errorpage": {
|
||||
Errors: &dynamic.ErrorPage{
|
||||
Status: []string{"404", "500"},
|
||||
Status: []string{"404", "500"},
|
||||
StatusRewrites: map[string]int{
|
||||
"404": 200,
|
||||
},
|
||||
Service: "default-errorpage-errorpage-service",
|
||||
Query: "query",
|
||||
},
|
||||
|
|
|
@ -68,11 +68,16 @@ type ErrorPage struct {
|
|||
// as ranges by separating two codes with a dash (500-599),
|
||||
// or a combination of the two (404,418,500-599).
|
||||
Status []string `json:"status,omitempty"`
|
||||
// StatusRewrites defines a mapping of status codes that should be returned instead of the original error status codes.
|
||||
// For example: "418": 404 or "410-418": 404
|
||||
StatusRewrites map[string]int `json:"statusRewrites,omitempty"`
|
||||
// Service defines the reference to a Kubernetes Service that will serve the error page.
|
||||
// More info: https://doc.traefik.io/traefik/v3.3/middlewares/http/errorpages/#service
|
||||
Service Service `json:"service,omitempty"`
|
||||
// Query defines the URL for the error page (hosted by service).
|
||||
// The {status} variable can be used in order to insert the status code in the URL.
|
||||
// The {originalStatus} variable can be used in order to insert the upstream status code in the URL.
|
||||
// The {url} variable can be used in order to insert the escaped request URL.
|
||||
Query string `json:"query,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -229,6 +229,13 @@ func (in *ErrorPage) DeepCopyInto(out *ErrorPage) {
|
|||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.StatusRewrites != nil {
|
||||
in, out := &in.StatusRewrites, &out.StatusRewrites
|
||||
*out = make(map[string]int, len(*in))
|
||||
for key, val := range *in {
|
||||
(*out)[key] = val
|
||||
}
|
||||
}
|
||||
in.Service.DeepCopyInto(&out.Service)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue