mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
admin,templates,core: Minor enhancements and error handling (#3607)
* fix 2 possible bugs * handle unhandled errors
This commit is contained in:
parent
514eef33fe
commit
af5c148ed1
4 changed files with 14 additions and 5 deletions
12
admin.go
12
admin.go
|
@ -18,6 +18,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"expvar"
|
"expvar"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -235,15 +236,20 @@ func replaceAdmin(cfg *Config) error {
|
||||||
MaxHeaderBytes: 1024 * 64,
|
MaxHeaderBytes: 1024 * 64,
|
||||||
}
|
}
|
||||||
|
|
||||||
go adminServer.Serve(ln)
|
adminLogger := Log().Named("admin")
|
||||||
|
go func() {
|
||||||
|
if err := adminServer.Serve(ln); !errors.Is(err, http.ErrServerClosed) {
|
||||||
|
adminLogger.Error("admin server shutdown for unknown reason", zap.Error(err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
Log().Named("admin").Info("admin endpoint started",
|
adminLogger.Info("admin endpoint started",
|
||||||
zap.String("address", addr.String()),
|
zap.String("address", addr.String()),
|
||||||
zap.Bool("enforce_origin", adminConfig.EnforceOrigin),
|
zap.Bool("enforce_origin", adminConfig.EnforceOrigin),
|
||||||
zap.Strings("origins", handler.allowedOrigins))
|
zap.Strings("origins", handler.allowedOrigins))
|
||||||
|
|
||||||
if !handler.enforceHost {
|
if !handler.enforceHost {
|
||||||
Log().Named("admin").Warn("admin endpoint on open interface; host checking disabled",
|
adminLogger.Warn("admin endpoint on open interface; host checking disabled",
|
||||||
zap.String("address", addr.String()))
|
zap.String("address", addr.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
caddy.go
2
caddy.go
|
@ -471,7 +471,7 @@ func stopAndCleanup() error {
|
||||||
}
|
}
|
||||||
certmagic.CleanUpOwnLocks()
|
certmagic.CleanUpOwnLocks()
|
||||||
if pidfile != "" {
|
if pidfile != "" {
|
||||||
os.Remove(pidfile)
|
return os.Remove(pidfile)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,6 +401,9 @@ func leastRequests(upstreams []*Upstream) *Upstream {
|
||||||
best = append(best, upstream)
|
best = append(best, upstream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(best) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return best[weakrand.Intn(len(best))]
|
return best[weakrand.Intn(len(best))]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ func TestCookie(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// cookie with optional fields
|
// cookie with optional fields
|
||||||
cookie: &http.Cookie{Name: "cookie", Value: "cookieValue", Path: "/path", Domain: "https://localhost", Expires: (time.Now().Add(10 * time.Minute)), MaxAge: 120},
|
cookie: &http.Cookie{Name: "cookie", Value: "cookieValue", Path: "/path", Domain: "https://localhost", Expires: time.Now().Add(10 * time.Minute), MaxAge: 120},
|
||||||
cookieName: "cookie",
|
cookieName: "cookie",
|
||||||
expect: "cookieValue",
|
expect: "cookieValue",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue