Repository navigation
Add payload_format raw: send the NATS payload as the event data (#143) - #154
Merged
Merged
Conversation
An event's data was always the JSON envelope {"topic","payload","time"},
so clients that only want the payload had to unwrap it, and plain-text
payloads arrived as escaped JSON strings.
payload_format raw writes the NATS payload itself: one data line per
line of it, which EventSource joins with "\n" again (an empty payload is
one empty data line and still dispatches an event). SSE data is UTF-8
text, and a carriage return ends a line. So a payload that is not valid
UTF-8, or holds a carriage return, cannot be sent: it is dropped, logged
and counted as nuts_messages_dropped_total{reason="raw_not_text"}. An
oversized payload keeps its raw_payload reason. The default, envelope,
changes nothing.
Closes #143
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #143.
An event's data was always the JSON envelope
{"topic","payload","time"}. Clients that only want the payload had to unwrap it, plain-text payloads arrived as escaped JSON strings, and the envelope cost 120–150 bytes ofmax_event_size.Changes
payload_format envelope | raw, defaultenvelope.data:line per line of it, which EventSource joins with\nagain. An empty payload is one emptydata:line and still dispatches an event.id:stays last (M11-11: Delivery visibility nits — id-first frames vs eager SSE parsers, invisible intentional skips, unattributable slow-consumer drops #107). Theconnectedandresetevents keep their JSON data.nuts_messages_dropped_total{reason="raw_not_text"}. An oversized payload keeps itsraw_payloadreason.caddyfile.go, validated and defaulted inprovision.go. Documented in the README (listing,payload_formatsection, event format, the metrics row), CONFIGURATION, the website, metrics help and the CHANGELOG. A new/rawroute in Caddyfile.test.Tests
TestFormatMessageEvent_RawPayload: exact frames for single-line, multi-line, trailing-newline, empty and non-ASCII payloads; drops for CR, CRLF and invalid UTF-8; oversize precedence; the drop's metric and log.FuzzFormatMessageEventMatchesReferencenow also varies raw mode, with an independent reference. It adds a round-trip property: whenever raw mode keeps a message, what EventSource makes of the frame is exactly the payload. 30 s ran clean.TestHandler_RawPayloadFormat, against a real server: a multi-line payload arrives intact, a CR payload is dropped, and the stream goes on./raw; 33/33. The full suite passes under-race; lint is clean.caddyfile.go40/0,provision.go207/0 (16 not covered, the baseline's),serve.go215/0./raw?topic=numbersgivesdata: {"number":50};/eventsgives the envelope.🤖 Generated with Claude Code