aboutsummaryrefslogtreecommitdiff
path: root/internal/accept_encoding.go
blob: 9eca7ed132b7e188fb82163de0ed2b67df171c39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)
	})
}