Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
http: Ensure primary routes always get compiled (fix #2972)
Including servers for HTTP->HTTPS redirects which do not get provisioned like the rest.
Matthew Holt committed
Jan 11, 2020 at 00:33 UTC
8be1f0ea668492000cdefbd937e0359bdc24bfc1
1 file changed
+10
-7
modules/caddyhttp/caddyhttp.go
+10
-7
@@ -164,6 +164,7 @@ func (app *App) Provision(ctx caddy.Context) error {
164
srv.Listen[i] = lnOut
165
}
166
167
+ primaryRoute := emptyHandler
168
if srv.Routes != nil {
169
err := srv.Routes.Provision(ctx)
170
if err != nil {
@@ -171,8 +172,9 @@ func (app *App) Provision(ctx caddy.Context) error {
172
}
173
// pre-compile the handler chain, and be sure to wrap it in our
174
// route handler so that important security checks are done, etc.
174
- srv.primaryHandlerChain = srv.wrapPrimaryRoute(srv.Routes.Compile())
175
+ srv.primaryHandlerChain = srv.Routes.Compile()
176
}
177
+ srv.primaryHandlerChain = srv.wrapPrimaryRoute(primaryRoute)
178
179
if srv.Errors != nil {
180
err := srv.Errors.Routes.Provision(ctx)
@@ -504,7 +506,7 @@ func (app *App) automaticHTTPS() error {
506
// if there are HTTP->HTTPS redirects to add, do so now
507
if len(lnAddrRedirRoutes) > 0 {
508
var redirServerAddrs []string
507
- var redirRoutes []Route
509
+ var redirRoutes RouteList
510
511
// for each redirect listener, see if there's already a
512
// server configured to listen on that exact address; if so,
@@ -539,11 +541,12 @@ func (app *App) automaticHTTPS() error {
541
// rest of the redirects
542
if len(redirServerAddrs) > 0 {
543
app.Servers["remaining_auto_https_redirects"] = &Server{
542
- Listen: redirServerAddrs,
543
- Routes: redirRoutes,
544
- tlsApp: tlsApp, // required to solve HTTP challenge
545
- logger: app.logger.Named("log"),
546
- errorLogger: app.logger.Named("log.error"),
544
+ Listen: redirServerAddrs,
545
+ Routes: redirRoutes,
546
+ tlsApp: tlsApp, // required to solve HTTP challenge
547
+ logger: app.logger.Named("log"),
548
+ errorLogger: app.logger.Named("log.error"),
549
+ primaryHandlerChain: redirRoutes.Compile(),
550
}
551
}
552
}