Repository navigation
Add event_type: name SSE events after their topic or a header (#142) - #153
Merged
Merged
Conversation
Every message went out as `event: message`, with its topic inside the JSON data, so a page handled all of them in one listener and routed them itself. event_type topic names each event after its topic, without topic_prefix. event_type header <name> uses that header of the NATS message. A name must be 1 to 100 bytes of [A-Za-z0-9._:-] and must not be one NUTS or EventSource uses itself (connected, reset, open, error): an event named error would reach the page's onerror handler. Otherwise, and for a message without the header, the event keeps the name message. The default, message, changes nothing. Closes #142 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 #142.
Every message went out as
event: message, with its topic inside the JSON data. A page therefore handled everything in one listener and routed it itself.Changes
event_type:message(the default): nothing changes.topic: the event is named after the message's topic, withouttopic_prefix, so a page can calladdEventListener('orders', …).header <name>: the event is named after that header of the NATS message. NATS header names are case-sensitive.message. A name must be 1–100 bytes of[A-Za-z0-9._:-]. It must also not be one of the reserved names:connected(the handshake),reset(Send the recreated-stream reset as a reset event (#133 follow-up) #147),openorerror. An event namederrorwould reach the page'sonerroras if the connection had failed. Otherwise, or when the header is missing, the event is namedmessage. The JSON data never changes.caddyfile.go(event_type header <name>, with an error for a missing name or an extra argument).provision.go. The JSON fields areevent_typeandevent_type_header; a header name without header mode, or an invalid header name, is rejected.event_typesection, event format), CONFIGURATION, the website listing and the CHANGELOG./typedroute in Caddyfile.test runsevent_type topic.Tests
TestIsUsableEventNameandTestIsValidHeaderNametables.TestHandler_EventName, over every mode and fallback, including a header with an embedded\nevent: forged.FuzzFormatMessageEventMatchesReferencenow also varies the event-type mode and the header value. It is checked against a regex-based reference implementation; 20 s of fuzzing ran clean. There is no committed corpus with the old signature.TestHandler_EventTypeFromTheTopicOrAHeader, against a real server: a header set on the published NATS message names the event, and one without it falls back tomessage./typed; 32/32. The full suite passes under-race, and staticcheck and golangci-lint are clean.helpers.go128 killed, 0 lived (12 not covered: the formatter's escaping cases, already checked by hand in the baseline);caddyfile.go40/0;provision.go206/0 (16 not covered, the baseline's);serve.go209/0./typed?topic=numbers&topic=lettersgivesconnected, letters, numbers, letters, …./eventskeepsmessage.🤖 Generated with Claude Code