You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Single broadcast API mangles JSON bodies that aren't plain objects #2378
TL;DR: POST /api/broadcast/:topic/events/:event works out the payload type from keys in the parsed body instead of from Content-Type, so two kinds of JSON body come out wrong:
A body that isn't an object ([1,2,3], "hello", 42) returns 202, but subscribers get {"_json": [1,2,3]}. That's how Plug wraps non-object JSON, and it's passed straight through.
An object with a _binary key is treated as a binary payload: v2 subscribers get a binary frame containing only the _binary value, and v1 subscribers get nothing.
curl -X POST "$REALTIME_URL/api/broadcast/room/events/msg" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '[1,2,3]'# subscribers receive {"_json":[1,2,3]}
curl -X POST "$REALTIME_URL/api/broadcast/room/events/msg" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"_binary":"x","other":1}'# v2 subscribers get a binary "x", v1 subscribers get nothing
#1864 says the content type decides the payload type, and the schema describes the body as a JSON object, so non-object bodies should probably get a 422.
Activity