Remove HTTP method checks
This is enforced by the router now.
This commit is contained in:
parent
d34f90a4b8
commit
3bbde04774
2 changed files with 2 additions and 15 deletions
10
main.go
10
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,
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Reference in a new issue