feat: add SSE (Server-Sent Events) support#59
Merged
Conversation
- Add SSEMessageEvent, SSECallbacks, SSEConfig types - Add parseSSEStream method for parsing SSE response - Add sse() convenience method for creating SSE connections - Support custom headers (unlike native EventSource) - Support POST requests and all HTTP methods - Support interceptors integration - Update README with SSE examples (EN & ZH)
- Remove docs directory (now auto-generated by CI) - Accept main branch changes for .gitignore and doc.yaml
- Refactored SSE promise handling to avoid circular dependency - Used variable to store abort handler for proper cleanup
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.
PR: feat: add SSE (Server-Sent Events) support
Summary
Added SSE (Server-Sent Events) support to the Request class, enabling streaming HTTP connections with a clean, composable API.
Motivation
Previously, the Request class only supported standard HTTP requests without streaming capabilities. This PR adds SSE support, which is essential for:
Key Features
1. Based on Fetch API (not native EventSource)
Unlike the browser's native
EventSource, this implementation:2. New Types Added
3. New Method:
sse()4. POST SSE Example (AI Streaming)
5. Interceptor Support
SSE requests automatically include headers added by request interceptors:
Implementation Details
SSE Parser
:)event:,data:,id:, andretry:fieldsMemory Management
AbortControllerfor clean cancellationTesting
The implementation has been tested with:
Breaking Changes
None. This is a purely additive feature.
Documentation
Updated both English and Chinese README files with:
Checklist
PR Link
Create PR: https://github.com/cenova-labs/utils/pull/new/feature/sse-support