From c48513b2bebd01ab29143e6ad7e89f2adfa4bd4d Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 13 May 2022 13:36:39 -0700 Subject: [PATCH] tsweb: support recording unabridged HTTP status codes as well. Signed-off-by: David Anderson --- tsweb/tsweb.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tsweb/tsweb.go b/tsweb/tsweb.go index 91baec0ec..191a1e9e3 100644 --- a/tsweb/tsweb.go +++ b/tsweb/tsweb.go @@ -21,6 +21,7 @@ "path/filepath" "reflect" "runtime" + "strconv" "strings" "time" @@ -88,7 +89,6 @@ func AllowDebugAccess(r *http.Request) bool { return false } - // AcceptsEncoding reports whether r accepts the named encoding // ("gzip", "br", etc). func AcceptsEncoding(r *http.Request, enc string) bool { @@ -192,6 +192,10 @@ type HandlerOptions struct { // of status codes for handled responses. // The keys are "1xx", "2xx", "3xx", "4xx", and "5xx". StatusCodeCounters *expvar.Map + // If non-nil, StatusCodeCountersFull maintains counters of status + // codes for handled responses. + // The keys are HTTP numeric response codes e.g. 200, 404, ... + StatusCodeCountersFull *expvar.Map } // ReturnHandlerFunc is an adapter to allow the use of ordinary @@ -301,6 +305,10 @@ func (h retHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { key := fmt.Sprintf("%dxx", msg.Code/100) h.opts.StatusCodeCounters.Add(key, 1) } + + if h.opts.StatusCodeCountersFull != nil { + h.opts.StatusCodeCountersFull.Add(strconv.Itoa(msg.Code), 1) + } } // loggingResponseWriter wraps a ResponseWriter and record the HTTP