Files
Gogs/internal/app/metrics.go
ᴊᴏᴇ ᴄʜᴇɴ 59e9fa191b chore: remove all MIT license file headers (#8083)
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2026-01-08 19:32:15 -05:00

30 lines
575 B
Go

package app
import (
"net/http"
"gopkg.in/macaron.v1"
"gogs.io/gogs/internal/authutil"
"gogs.io/gogs/internal/conf"
)
func MetricsFilter() macaron.Handler {
return func(w http.ResponseWriter, r *http.Request) {
if !conf.Prometheus.Enabled {
w.WriteHeader(http.StatusNotFound)
return
}
if !conf.Prometheus.EnableBasicAuth {
return
}
username, password := authutil.DecodeBasic(r.Header)
if username != conf.Prometheus.BasicAuthUsername || password != conf.Prometheus.BasicAuthPassword {
w.WriteHeader(http.StatusForbidden)
return
}
}
}