From 9ec5e6c40b0c0e4a8009acbdd5dfea8c0e60cfcd Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 18 Nov 2020 04:50:06 +0800 Subject: Move metrics from macaron to chi (#13601) --- routers/metrics.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'routers/metrics.go') 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) } -- cgit v1.2.3