http: Ensure primary routes always get compiled (fix #2972)

Including servers for HTTP->HTTPS redirects which do not get provisioned
like the rest.
This commit is contained in:
Matthew Holt 2020-01-11 00:33:47 -07:00
parent 2eda21ec6d
commit 8be1f0ea66
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
1 changed files with 10 additions and 7 deletions

View File

@ -164,6 +164,7 @@ func (app *App) Provision(ctx caddy.Context) error {
srv.Listen[i] = lnOut
}
primaryRoute := emptyHandler
if srv.Routes != nil {
err := srv.Routes.Provision(ctx)
if err != nil {
@ -171,8 +172,9 @@ func (app *App) Provision(ctx caddy.Context) error {
}
// pre-compile the handler chain, and be sure to wrap it in our
// route handler so that important security checks are done, etc.
srv.primaryHandlerChain = srv.wrapPrimaryRoute(srv.Routes.Compile())
srv.primaryHandlerChain = srv.Routes.Compile()
}
srv.primaryHandlerChain = srv.wrapPrimaryRoute(primaryRoute)
if srv.Errors != nil {
err := srv.Errors.Routes.Provision(ctx)
@ -504,7 +506,7 @@ func (app *App) automaticHTTPS() error {
// if there are HTTP->HTTPS redirects to add, do so now
if len(lnAddrRedirRoutes) > 0 {
var redirServerAddrs []string
var redirRoutes []Route
var redirRoutes RouteList
// for each redirect listener, see if there's already a
// server configured to listen on that exact address; if so,
@ -544,6 +546,7 @@ func (app *App) automaticHTTPS() error {
tlsApp: tlsApp, // required to solve HTTP challenge
logger: app.logger.Named("log"),
errorLogger: app.logger.Named("log.error"),
primaryHandlerChain: redirRoutes.Compile(),
}
}
}