mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-13 10:42:16 -04:00
diagnostics: AppendUnique(), restructure sets, add metrics, fix bugs
This commit is contained in:
@@ -24,6 +24,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/mholt/caddy/diagnostics"
|
||||
)
|
||||
|
||||
// tlsHandler is a http.Handler that will inject a value
|
||||
@@ -97,6 +99,13 @@ func (h *tlsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if checked {
|
||||
r = r.WithContext(context.WithValue(r.Context(), MitmCtxKey, mitm))
|
||||
if mitm {
|
||||
go diagnostics.AppendUnique("mitm", "likely")
|
||||
} else {
|
||||
go diagnostics.AppendUnique("mitm", "unlikely")
|
||||
}
|
||||
} else {
|
||||
go diagnostics.AppendUnique("mitm", "unknown")
|
||||
}
|
||||
|
||||
if mitm && h.closeOnMITM {
|
||||
|
||||
@@ -29,7 +29,6 @@ import (
|
||||
"github.com/mholt/caddy/caddyfile"
|
||||
"github.com/mholt/caddy/caddyhttp/staticfiles"
|
||||
"github.com/mholt/caddy/caddytls"
|
||||
"github.com/mholt/caddy/diagnostics"
|
||||
)
|
||||
|
||||
const serverType = "http"
|
||||
@@ -206,8 +205,6 @@ func (h *httpContext) MakeServers() ([]caddy.Server, error) {
|
||||
}
|
||||
}
|
||||
|
||||
diagnostics.Set("num_sites", len(h.siteConfigs))
|
||||
|
||||
// we must map (group) each config to a bind address
|
||||
groups, err := groupSiteConfigsByListenAddr(h.siteConfigs)
|
||||
if err != nil {
|
||||
|
||||
@@ -346,7 +346,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}()
|
||||
|
||||
go diagnostics.AppendUniqueString("user_agent", r.Header.Get("User-Agent"))
|
||||
go diagnostics.AppendUnique("user_agent", r.Header.Get("User-Agent"))
|
||||
|
||||
// copy the original, unchanged URL into the context
|
||||
// so it can be referenced by middlewares
|
||||
|
||||
Reference in New Issue
Block a user