feat: support Server-Sent Events as a streaming content format#2232
Merged
Conversation
- Add StreamingContentFormat.ServerSentEvents and map text/event-stream to it in DetectStreamingFormat - Stream each SSE data event into IAsyncEnumerable<T> via SseParser, deserializing payloads through the existing source-generated/reflection JSON metadata path so it stays trim and Native AOT clean - Reference System.Net.ServerSentEvents on targets that lack it in-box (net4x/netstandard2.0/net8.0/net9.0); net10.0+ use the framework reference - Inherit both generated and reflection execution paths through the shared streaming seam (no generator change) - Cover generated/reflection paths and source-gen/reflection serializers; document in README and breaking-changes
…rmat # Conflicts: # docs/breaking-changes.md
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2232 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 182 182
Lines 9444 9453 +9
Branches 1772 1774 +2
=========================================
+ Hits 9444 9453 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…rmat # Conflicts: # docs/breaking-changes.md
ChrisPulman
approved these changes
Jul 15, 2026
…rmat # Conflicts: # docs/breaking-changes.md # src/Refit/RequestExecutionHelpers.cs
…rmat # Conflicts: # docs/breaking-changes.md
…rmat # Conflicts: # docs/breaking-changes.md
|
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.



What kind of change does this PR introduce?
Feature - adds
text/event-stream(Server-Sent Events) as a first-class streaming content format.What is the new behavior?
A Refit method declared as
IAsyncEnumerable<T>against an SSE endpoint now yields oneTper SSEdataevent, streamed live and unbuffered.StreamingContentFormat.ServerSentEventsenum member.DetectStreamingFormatmaps atext/event-streamresponse content type to the new format.SystemTextJsonContentSerializerparses each SSE event withSseParserand deserializes the event'sdatapayload toT(the event type/id envelope is dropped), reusing the same source-generated / reflectionJsonTypeInfo<T>path the serializer already uses, so it stays trim and Native AOT clean.System.Net.ServerSentEventspackage on the targets that lack it in-box (net4x / netstandard2.0 / net8.0 / net9.0); net10.0+ use the framework reference. This gives uniform behavior on every target framework.What is the current behavior?
Consuming SSE already worked but only by returning
Task<Stream>and feeding it toSystem.Net.ServerSentEvents.SseParsermanually. There was no typed, per-event streaming experience for SSE endpoints.Closes #2228
What might this PR break?
None expected. The change is additive: a new
StreamingContentFormat.ServerSentEventsenum member and aSystem.Net.ServerSentEventspackage reference on the targets that lack it in-box. Existing content formats and code are unchanged. If you need the raw event envelope (event type or id), returnTask<Stream>and useSystem.Net.ServerSentEvents.SseParserdirectly.Checklist
mainbranchAdditional information
DetectStreamingFormattext/event-streambranch and the serializer SSE branch.dotnet build Refit.slnx -c Release(all target frameworks) -> 0 warnings, 0 errors; fullRefit.Tests(net8.0) passes; generator tests pass with no snapshot change; 100% patch coverage on the changed lines.docs/breaking-changes.mdnotes the new enum member and package reference.