mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-14 14:56:27 +03:00
caddyhttp: Skip inserting HTTP->HTTPS redir if catch-all for both exist (#5051)
This commit is contained in:
parent
da8b7fe58f
commit
e3d04ff86b
1 changed files with 22 additions and 12 deletions
|
@ -378,20 +378,30 @@ redirServersLoop:
|
||||||
// we'll create a new server for all the listener addresses
|
// we'll create a new server for all the listener addresses
|
||||||
// that are unused and serve the remaining redirects from it
|
// that are unused and serve the remaining redirects from it
|
||||||
for _, srv := range app.Servers {
|
for _, srv := range app.Servers {
|
||||||
if srv.hasListenerAddress(redirServerAddr) {
|
// only look at servers which listen on an address which
|
||||||
|
// we want to add redirects to
|
||||||
|
if !srv.hasListenerAddress(redirServerAddr) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// find the index of the route after the last route with a host
|
// find the index of the route after the last route with a host
|
||||||
// matcher, then insert the redirects there, but before any
|
// matcher, then insert the redirects there, but before any
|
||||||
// user-defined catch-all routes
|
// user-defined catch-all routes
|
||||||
// see https://github.com/caddyserver/caddy/issues/3212
|
// see https://github.com/caddyserver/caddy/issues/3212
|
||||||
insertIndex := srv.findLastRouteWithHostMatcher()
|
insertIndex := srv.findLastRouteWithHostMatcher()
|
||||||
|
|
||||||
|
// add the redirects at the insert index, except for when
|
||||||
|
// we have a catch-all for HTTPS, in which case the user's
|
||||||
|
// defined catch-all should take precedence. See #4829
|
||||||
|
if len(uniqueDomainsForCerts) != 0 {
|
||||||
srv.Routes = append(srv.Routes[:insertIndex], append(routes, srv.Routes[insertIndex:]...)...)
|
srv.Routes = append(srv.Routes[:insertIndex], append(routes, srv.Routes[insertIndex:]...)...)
|
||||||
|
}
|
||||||
|
|
||||||
// append our catch-all route in case the user didn't define their own
|
// append our catch-all route in case the user didn't define their own
|
||||||
srv.Routes = appendCatchAll(srv.Routes)
|
srv.Routes = appendCatchAll(srv.Routes)
|
||||||
|
|
||||||
continue redirServersLoop
|
continue redirServersLoop
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// no server with this listener address exists;
|
// no server with this listener address exists;
|
||||||
// save this address and route for custom server
|
// save this address and route for custom server
|
||||||
|
|
Loading…
Reference in a new issue