mirror of
https://github.com/gogs/gogs.git
synced 2025-12-20 15:20:01 +01:00
metrics: add initial Prometheus support (#4141)
This commit is contained in:
@@ -5,13 +5,16 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/go-macaron/csrf"
|
||||
"gopkg.in/macaron.v1"
|
||||
|
||||
"github.com/gogs/gogs/pkg/auth"
|
||||
"github.com/gogs/gogs/pkg/setting"
|
||||
"github.com/gogs/gogs/pkg/tool"
|
||||
)
|
||||
|
||||
type ToggleOptions struct {
|
||||
@@ -92,3 +95,18 @@ func Toggle(options *ToggleOptions) macaron.Handler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RequireBasicAuth verifies HTTP Basic Authentication header with given credentials
|
||||
func (c *Context) RequireBasicAuth(username, password string) {
|
||||
fields := strings.Fields(c.Req.Header.Get("Authorization"))
|
||||
if len(fields) != 2 || fields[0] != "Basic" {
|
||||
c.Status(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
uname, passwd, _ := tool.BasicAuthDecode(fields[1])
|
||||
if uname != username || passwd != password {
|
||||
c.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user