diagnostics: AppendUnique(), restructure sets, add metrics, fix bugs

This commit is contained in:
Matthew Holt
2018-02-10 12:59:23 -07:00
parent 703cf7bf8b
commit 6b3c2212a1
10 changed files with 141 additions and 82 deletions
+9
View File
@@ -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 {
-3
View File
@@ -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 {
+1 -1
View File
@@ -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