diff options
| author | Xe Iaso <me@xeiaso.net> | 2023-10-25 17:03:18 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2023-10-25 17:03:18 -0400 |
| commit | f736765706c4b28946130929d4e5a7e0d28256d5 (patch) | |
| tree | 044bfc0504a44dcbbdf04b1665112ae24379b0af | |
| parent | 8ef825b08789ecdc65e216089fa26293c762bf49 (diff) | |
| download | xesite-f736765706c4b28946130929d4e5a7e0d28256d5.tar.xz xesite-f736765706c4b28946130929d4e5a7e0d28256d5.zip | |
internal: add middleware to track the use of accept-encoding headers
Signed-off-by: Xe Iaso <me@xeiaso.net>
| -rw-r--r-- | cmd/xesite/main.go | 1 | ||||
| -rw-r--r-- | internal/accept_encoding.go | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/cmd/xesite/main.go b/cmd/xesite/main.go index 3c0b2af..bf01514 100644 --- a/cmd/xesite/main.go +++ b/cmd/xesite/main.go @@ -120,6 +120,7 @@ func main() { var h http.Handler = mux h = internal.ClackSet(fs.Clacks()).Middleware(h) h = internal.CacheHeader(h) + h = internal.AcceptEncodingMiddleware(h) slog.Info("starting server", "bind", *bind) log.Fatal(http.Serve(ln, h)) diff --git a/internal/accept_encoding.go b/internal/accept_encoding.go new file mode 100644 index 0000000..9eca7ed --- /dev/null +++ b/internal/accept_encoding.go @@ -0,0 +1,23 @@ +package internal + +import ( + "expvar" + "net/http" + + "tailscale.com/metrics" +) + +var ( + acceptEncodings = &metrics.LabelMap{Label: "encoding"} +) + +func init() { + expvar.Publish("gauge_xesite_accept_encoding", acceptEncodings) +} + +func AcceptEncodingMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + acceptEncodings.Add(r.Header.Get("Accept-Encoding"), 1) + next.ServeHTTP(w, r) + }) +} |
