aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/anubis.go10
-rw-r--r--lib/policy/config/config.go3
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/anubis.go b/lib/anubis.go
index c61b110..939262a 100644
--- a/lib/anubis.go
+++ b/lib/anubis.go
@@ -241,6 +241,10 @@ func (s *Server) MaybeReverseProxy(w http.ResponseWriter, r *http.Request) {
return
case config.RuleChallenge:
lg.Debug("challenge requested")
+ case config.RuleBenchmark:
+ lg.Debug("serving benchmark page")
+ s.RenderBench(w, r)
+ return
default:
s.ClearCookie(w)
templ.Handler(web.Base("Oh noes!", web.ErrorPage("Other internal server error (contact the admin)")), templ.WithStatus(http.StatusInternalServerError)).ServeHTTP(w, r)
@@ -334,6 +338,12 @@ func (s *Server) RenderIndex(w http.ResponseWriter, r *http.Request) {
handler.ServeHTTP(w, r)
}
+func (s *Server) RenderBench(w http.ResponseWriter, r *http.Request) {
+ templ.Handler(
+ web.Base("Benchmarking Anubis!", web.Bench()),
+ ).ServeHTTP(w, r)
+}
+
func (s *Server) MakeChallenge(w http.ResponseWriter, r *http.Request) {
lg := slog.With("user_agent", r.UserAgent(), "accept_language", r.Header.Get("Accept-Language"), "priority", r.Header.Get("Priority"), "x-forwarded-for", r.Header.Get("X-Forwarded-For"), "x-real-ip", r.Header.Get("X-Real-Ip"))
diff --git a/lib/policy/config/config.go b/lib/policy/config/config.go
index b23af70..e8f5161 100644
--- a/lib/policy/config/config.go
+++ b/lib/policy/config/config.go
@@ -25,6 +25,7 @@ const (
RuleAllow Rule = "ALLOW"
RuleDeny Rule = "DENY"
RuleChallenge Rule = "CHALLENGE"
+ RuleBenchmark Rule = "DEBUG_BENCHMARK"
)
type Algorithm string
@@ -80,7 +81,7 @@ func (b BotConfig) Valid() error {
}
switch b.Action {
- case RuleAllow, RuleChallenge, RuleDeny:
+ case RuleAllow, RuleBenchmark, RuleChallenge, RuleDeny:
// okay
default:
errs = append(errs, fmt.Errorf("%w: %q", ErrUnknownAction, b.Action))