diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-11-18 04:50:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-17 15:50:06 -0500 |
commit | 9ec5e6c40b0c0e4a8009acbdd5dfea8c0e60cfcd (patch) | |
tree | 8694fa49472463f458cb01218df803201196924e /routers/metrics.go | |
parent | 75ebf7c5bd48e64d58aef9892ce6b6fbf69e5f1a (diff) | |
download | gitea-9ec5e6c40b0c0e4a8009acbdd5dfea8c0e60cfcd.tar.gz gitea-9ec5e6c40b0c0e4a8009acbdd5dfea8c0e60cfcd.zip |
Move metrics from macaron to chi (#13601)
Diffstat (limited to 'routers/metrics.go')
-rw-r--r-- | routers/metrics.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/routers/metrics.go b/routers/metrics.go index f2381c2745..db2fb8de44 100644 --- a/routers/metrics.go +++ b/routers/metrics.go @@ -6,29 +6,29 @@ package routers import ( "crypto/subtle" + "net/http" - "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "github.com/prometheus/client_golang/prometheus/promhttp" ) // Metrics validate auth token and render prometheus metrics -func Metrics(ctx *context.Context) { +func Metrics(resp http.ResponseWriter, req *http.Request) { if setting.Metrics.Token == "" { - promhttp.Handler().ServeHTTP(ctx.Resp, ctx.Req.Request) + promhttp.Handler().ServeHTTP(resp, req) return } - header := ctx.Req.Header.Get("Authorization") + header := req.Header.Get("Authorization") if header == "" { - ctx.Error(401) + http.Error(resp, "", 401) return } got := []byte(header) want := []byte("Bearer " + setting.Metrics.Token) if subtle.ConstantTimeCompare(got, want) != 1 { - ctx.Error(401) + http.Error(resp, "", 401) return } - promhttp.Handler().ServeHTTP(ctx.Resp, ctx.Req.Request) + promhttp.Handler().ServeHTTP(resp, req) } |