httpcaddyfile: Add optional status code argument to handle_errors directive (#5965)

Co-authored-by: Aziz Rmadi <azizrmadi@Azizs-MacBook-Air.local>
This commit is contained in:
Aziz Rmadi 2024-01-16 00:24:17 -06:00 committed by GitHub
parent 5e2f1b5ced
commit 4181c79a81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 942 additions and 2 deletions

View file

@ -774,10 +774,19 @@ func (st *ServerType) serversFromPairings(
if srv.Errors == nil {
srv.Errors = new(caddyhttp.HTTPErrorConfig)
}
sort.SliceStable(errorSubrouteVals, func(i, j int) bool {
sri, srj := errorSubrouteVals[i].Value.(*caddyhttp.Subroute), errorSubrouteVals[j].Value.(*caddyhttp.Subroute)
if len(sri.Routes[0].MatcherSetsRaw) == 0 && len(srj.Routes[0].MatcherSetsRaw) != 0 {
return false
}
return true
})
errorsSubroute := &caddyhttp.Subroute{}
for _, val := range errorSubrouteVals {
sr := val.Value.(*caddyhttp.Subroute)
srv.Errors.Routes = appendSubrouteToRouteList(srv.Errors.Routes, sr, matcherSetsEnc, p, warnings)
errorsSubroute.Routes = append(errorsSubroute.Routes, sr.Routes...)
}
srv.Errors.Routes = appendSubrouteToRouteList(srv.Errors.Routes, errorsSubroute, matcherSetsEnc, p, warnings)
}
// add log associations