Add JSON publishing support

This commit is contained in:
binwiederhier
2026-01-08 15:45:50 -05:00
parent 1ab7ca876c
commit 66ea25c18b
2 changed files with 15 additions and 0 deletions

View File

@@ -2027,6 +2027,9 @@ func (s *Server) transformBodyJSON(next handleFunc) handleFunc {
if m.Firebase != "" {
r.Header.Set("X-Firebase", m.Firebase)
}
if m.SequenceID != "" {
r.Header.Set("X-Sequence-ID", m.SequenceID)
}
return next(w, r, v)
}
}

View File

@@ -727,6 +727,18 @@ func TestServer_PublishWithSIDViaGet(t *testing.T) {
require.Equal(t, "sid1", msg.SequenceID)
}
func TestServer_PublishAsJSON_WithSequenceID(t *testing.T) {
s := newTestServer(t, newTestConfig(t))
body := `{"topic":"mytopic","message":"A message","sequence_id":"my-sequence-123"}`
response := request(t, s, "PUT", "/", body, nil)
require.Equal(t, 200, response.Code)
msg := toMessage(t, response.Body.String())
require.NotEmpty(t, msg.ID)
require.Equal(t, "my-sequence-123", msg.SequenceID)
}
func TestServer_PublishWithInvalidSIDInPath(t *testing.T) {
s := newTestServer(t, newTestConfig(t))