mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-29 10:54:51 -04:00
Refactor how caddy.Context is stored and used
- Server types no longer need to store their own contexts; they are stored on the caddy.Instance, which means each context will be properly GC'ed when the instance is stopped. Server types should use type assertions to convert from caddy.Context to their concrete context type when they need to use it. - Pass the entire context into httpserver.GetConfig instead of only the Key field. - caddy.NewTestController now requires a server type string so it can create a controller with the proper concrete context associated with that server type. Tests still need more attention so that we can test the proper creation of startup functions, etc.
This commit is contained in:
@@ -4,37 +4,37 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
"github.com/mholt/caddy/caddytls"
|
||||
)
|
||||
|
||||
func activateHTTPS() error {
|
||||
// TODO: Is this loop a bug? Should we scope this method to just a single context? (restarts...?)
|
||||
for _, ctx := range contexts {
|
||||
// pre-screen each config and earmark the ones that qualify for managed TLS
|
||||
markQualifiedForAutoHTTPS(ctx.siteConfigs)
|
||||
func activateHTTPS(cctx caddy.Context) error {
|
||||
ctx := cctx.(*httpContext)
|
||||
|
||||
// place certificates and keys on disk
|
||||
for _, c := range ctx.siteConfigs {
|
||||
err := c.TLS.ObtainCert(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// pre-screen each config and earmark the ones that qualify for managed TLS
|
||||
markQualifiedForAutoHTTPS(ctx.siteConfigs)
|
||||
|
||||
// update TLS configurations
|
||||
err := enableAutoHTTPS(ctx.siteConfigs, true)
|
||||
// place certificates and keys on disk
|
||||
for _, c := range ctx.siteConfigs {
|
||||
err := c.TLS.ObtainCert(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// set up redirects
|
||||
ctx.siteConfigs = makePlaintextRedirects(ctx.siteConfigs)
|
||||
}
|
||||
|
||||
// update TLS configurations
|
||||
err := enableAutoHTTPS(ctx.siteConfigs, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// set up redirects
|
||||
ctx.siteConfigs = makePlaintextRedirects(ctx.siteConfigs)
|
||||
|
||||
// renew all relevant certificates that need renewal. this is important
|
||||
// to do right away so we guarantee that renewals aren't missed, and
|
||||
// also the user can respond to any potential errors that occur.
|
||||
err := caddytls.RenewManagedCertificates(true)
|
||||
err = caddytls.RenewManagedCertificates(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user