From 3bbde04774cdea84a9b9acfdb3224496e11df2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 21 Nov 2024 13:58:50 +0100 Subject: [PATCH] Remove HTTP method checks This is enforced by the router now. --- main.go | 10 ++-------- silence.go | 7 ------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 96bda73..e75e542 100644 --- a/main.go +++ b/main.go @@ -430,12 +430,6 @@ func (br *bridge) handleWebhooks(w http.ResponseWriter, r *http.Request) { ctx := r.Context() logger := br.logger.With(slog.String("handler", "/")) - if r.Method != http.MethodPost { - http.Error(w, "Only POST allowed", http.StatusMethodNotAllowed) - logger.Debug(fmt.Sprintf("Illegal HTTP method: expected %q, got %q", "POST", r.Method)) - return - } - contentType := r.Header.Get("Content-Type") if contentType != "application/json" { http.Error(w, "Only application/json allowed", http.StatusUnsupportedMediaType) @@ -586,8 +580,8 @@ func main() { logger.Info(fmt.Sprintf("Listening on %s, ntfy-alertmanager %s", cfg.HTTPAddress, version)) mux := http.NewServeMux() - mux.HandleFunc("/", bridge.handleWebhooks) - mux.HandleFunc("/silences", bridge.handleSilences) + mux.HandleFunc("POST /", bridge.handleWebhooks) + mux.HandleFunc("POST /silences", bridge.handleSilences) httpServer := &http.Server{ Addr: cfg.HTTPAddress, diff --git a/silence.go b/silence.go index d8060bb..66e1bbf 100644 --- a/silence.go +++ b/silence.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/base64" "encoding/json" - "fmt" "io" "log/slog" "net/http" @@ -40,12 +39,6 @@ type silenceResponse struct { func (br *bridge) handleSilences(w http.ResponseWriter, r *http.Request) { logger := br.logger.With(slog.String("handler", "/silences")) - if r.Method != http.MethodPost { - http.Error(w, "Only POST allowed", http.StatusMethodNotAllowed) - logger.Debug(fmt.Sprintf("Illegal HTTP method: expected %q, got %q", "POST", r.Method)) - return - } - b, err := io.ReadAll(r.Body) if err != nil { logger.Error("Failed to read body",