A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
838 B

  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package routers
  5. import (
  6. "crypto/subtle"
  7. "net/http"
  8. "code.gitea.io/gitea/modules/setting"
  9. "github.com/prometheus/client_golang/prometheus/promhttp"
  10. )
  11. // Metrics validate auth token and render prometheus metrics
  12. func Metrics(resp http.ResponseWriter, req *http.Request) {
  13. if setting.Metrics.Token == "" {
  14. promhttp.Handler().ServeHTTP(resp, req)
  15. return
  16. }
  17. header := req.Header.Get("Authorization")
  18. if header == "" {
  19. http.Error(resp, "", 401)
  20. return
  21. }
  22. got := []byte(header)
  23. want := []byte("Bearer " + setting.Metrics.Token)
  24. if subtle.ConstantTimeCompare(got, want) != 1 {
  25. http.Error(resp, "", 401)
  26. return
  27. }
  28. promhttp.Handler().ServeHTTP(resp, req)
  29. }