notification: B3 — Content-Type header + URL trim

Fixes flagged in spec review of f0a323e: ntfy POSTs need explicit
Content-Type: text/plain (the spec calls for it; ntfy works without
but explicit beats inferred); trim trailing slashes from server URL
to avoid double-slash when operators paste 'https://ntfy.sh/'.
This commit is contained in:
2026-05-04 19:38:16 +01:00
parent f0a323ef91
commit a99864c649
2 changed files with 15 additions and 7 deletions
+4 -1
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"
)
@@ -49,13 +50,15 @@ func (c *NtfyChannel) Kind() string { return "ntfy" }
// with ntfy headers. Returns (statusCode, latency, err). 4xx/5xx
// responses are returned as errors with the status code set.
func (c *NtfyChannel) Send(ctx context.Context, p Payload) (int, time.Duration, error) {
url := c.cfg.ServerURL + "/" + c.cfg.Topic
server := strings.TrimRight(c.cfg.ServerURL, "/")
url := server + "/" + c.cfg.Topic
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBufferString(p.Message))
if err != nil {
return 0, 0, fmt.Errorf("ntfy: build request: %w", err)
}
req.Header.Set("Content-Type", "text/plain")
req.Header.Set("Title", fmt.Sprintf("[%s] %s %s", p.Severity, p.HostName, p.Kind))
req.Header.Set("Tags", p.Severity+","+p.Kind)
req.Header.Set("Priority", priorityForSeverity(p.Severity, c.defaultPriority))