diff --git a/server/server.go b/server/server.go index eb0fd120..eb4e5504 100644 --- a/server/server.go +++ b/server/server.go @@ -1862,6 +1862,12 @@ func (s *Server) transformBodyJSON(next handleFunc) handleFunc { if m.Call != "" { r.Header.Set("X-Call", m.Call) } + if m.Cache != "" { + r.Header.Set("X-Cache", m.Cache) + } + if m.Firebase != "" { + r.Header.Set("X-Firebase", m.Firebase) + } return next(w, r, v) } } diff --git a/server/server_test.go b/server/server_test.go index ef9157cb..460b6deb 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -84,6 +84,22 @@ func TestServer_PublishWithFirebase(t *testing.T) { require.Equal(t, "my first message", sender.Messages()[0].APNS.Payload.CustomData["message"]) } +func TestServer_PublishWithoutFirebase(t *testing.T) { + sender := newTestFirebaseSender(10) + s := newTestServer(t, newTestConfig(t)) + s.firebaseClient = newFirebaseClient(sender, &testAuther{Allow: true}) + + response := request(t, s, "PUT", "/mytopic", "my first message", map[string]string{ + "firebase": "no", + }) + msg1 := toMessage(t, response.Body.String()) + require.NotEmpty(t, msg1.ID) + require.Equal(t, "my first message", msg1.Message) + + time.Sleep(100 * time.Millisecond) // Firebase publishing happens + require.Equal(t, 0, len(sender.Messages())) +} + func TestServer_PublishWithFirebase_WithoutUsers_AndWithoutPanic(t *testing.T) { // This tests issue #641, which used to panic before the fix @@ -1669,6 +1685,35 @@ func TestServer_PublishAsJSON_WithActions(t *testing.T) { require.Equal(t, "target_temp_f=65", m.Actions[1].Body) } +func TestServer_PublishAsJSON_NoCache(t *testing.T) { + s := newTestServer(t, newTestConfig(t)) + body := `{"topic":"mytopic","message": "this message is not cached","cache":"no"}` + response := request(t, s, "PUT", "/", body, nil) + msg := toMessage(t, response.Body.String()) + require.NotEmpty(t, msg.ID) + require.Equal(t, "this message is not cached", msg.Message) + require.Equal(t, int64(0), msg.Expires) + + response = request(t, s, "GET", "/mytopic/json?poll=1", "", nil) + messages := toMessages(t, response.Body.String()) + require.Empty(t, messages) +} + +func TestServer_PublishAsJSON_WithoutFirebase(t *testing.T) { + sender := newTestFirebaseSender(10) + s := newTestServer(t, newTestConfig(t)) + s.firebaseClient = newFirebaseClient(sender, &testAuther{Allow: true}) + + body := `{"topic":"mytopic","message": "my first message","firebase":"no"}` + response := request(t, s, "PUT", "/", body, nil) + msg1 := toMessage(t, response.Body.String()) + require.NotEmpty(t, msg1.ID) + require.Equal(t, "my first message", msg1.Message) + + time.Sleep(100 * time.Millisecond) // Firebase publishing happens + require.Equal(t, 0, len(sender.Messages())) +} + func TestServer_PublishAsJSON_Invalid(t *testing.T) { s := newTestServer(t, newTestConfig(t)) body := `{"topic":"mytopic",INVALID` diff --git a/server/types.go b/server/types.go index fb08fb05..b26df1a3 100644 --- a/server/types.go +++ b/server/types.go @@ -105,6 +105,8 @@ type publishMessage struct { Filename string `json:"filename"` Email string `json:"email"` Call string `json:"call"` + Cache string `json:"cache"` // use string as it defaults to true (or use &bool instead) + Firebase string `json:"firebase"` // use string as it defaults to true (or use &bool instead) Delay string `json:"delay"` }