Skip to content

Commit 4f19dd5

Browse files
authored
fix: gotify http method must be POST (#40)
Gotify expects messages to be delivered with `POST` method, not `GET` ([docs](https://gotify.net/docs/pushmsg)). Bug was introduced in 4d0ac34#diff-d1574fc19caffa382481ccc99b3b6509878e689a3f0a74e3e59f718d094e0a67L70-R58 (4 years ago) – typo error. This pr fixes #39
1 parent 68806e4 commit 4f19dd5

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

notifier/gotify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (hook *gotifyHook) send(msg string) error {
4646
form.Add("message", msg)
4747

4848
url := fmt.Sprintf("%s/message?token=%s", hook.AppURL, hook.AppToken)
49-
req, err := http.NewRequest(http.MethodGet, url, strings.NewReader(form.Encode()))
49+
req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(form.Encode()))
5050
if err != nil {
5151
return fmt.Errorf("failed to create a request: %w", err)
5252
}

notifier/gotify_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestGotifyFire(t *testing.T) {
5151
t.Run(tc.tname, func(t *testing.T) {
5252
is := is.New(t)
5353

54-
url, close := httpHelper(t, tc.tname, nil, tc.statusCode)
54+
url, close := httpHelper(t, tc.tname, http.MethodPost, nil, tc.statusCode)
5555
defer close()
5656

5757
hook, err := newGotifyhook(map[string]interface{}{

notifier/notifier_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import (
88
"github.com/matryer/is"
99
)
1010

11-
func httpHelper(t *testing.T, response string, headers map[string]string, statusCode int) (string, func()) {
11+
func httpHelper(t *testing.T, response string, requestMethod string, headers map[string]string, statusCode int) (string, func()) {
1212
is := is.New(t)
1313
is.Helper()
1414

1515
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
16+
is.Helper()
17+
18+
is.Equal(r.Method, requestMethod)
19+
1620
for k, v := range headers {
1721
w.Header().Add(k, v)
1822
}

notifier/telegram_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestTelegramHookFire(t *testing.T) {
4141
t.Run(tc.tname, func(t *testing.T) {
4242
is := is.New(t)
4343

44-
url, close := httpHelper(t, tc.tname, nil, tc.statusCode)
44+
url, close := httpHelper(t, tc.tname, http.MethodGet, nil, tc.statusCode)
4545
defer close()
4646

4747
hook, err := newTelegramHook(map[string]interface{}{

0 commit comments

Comments
 (0)