-
Notifications
You must be signed in to change notification settings - Fork 30
feat!: Replace hyper-specific interfaces with generic trait #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
keelerm84
merged 4 commits into
feat/hyper-as-feature
from
mk/sdk-1724/remove-hyper-dependency
Jan 9, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,8 @@ name: Run Release Please | |
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - "main" | ||
| - "feat/**" | ||
|
|
||
| jobs: | ||
| release-package: | ||
|
|
||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,41 +4,125 @@ | |
|
|
||
| Client for the [Server-Sent Events] protocol (aka [EventSource]). | ||
|
|
||
| This library focuses on the SSE protocol implementation. You provide the HTTP transport layer (hyper, reqwest, etc.), giving you full control over HTTP configuration like timeouts, TLS, and connection pooling. | ||
|
|
||
| [Server-Sent Events]: https://html.spec.whatwg.org/multipage/server-sent-events.html | ||
| [EventSource]: https://developer.mozilla.org/en-US/docs/Web/API/EventSource | ||
|
|
||
| ## Requirements | ||
|
|
||
| Requires tokio. | ||
| * Tokio async runtime | ||
| * An HTTP client library (hyper, reqwest, or custom) | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### 1. Add dependencies | ||
|
|
||
| ## Usage | ||
| ```toml | ||
| [dependencies] | ||
| eventsource-client = "0.17" | ||
| reqwest = { version = "0.12", features = ["stream"] } # or hyper v1 | ||
| futures = "0.3" | ||
| tokio = { version = "1", features = ["macros", "rt-multi-thread"] } | ||
| ``` | ||
|
|
||
| ### 2. Implement HttpTransport | ||
|
|
||
| Example that just prints the type of each event received: | ||
| Use one of our example implementations: | ||
|
|
||
| ```rust | ||
| use eventsource_client as es; | ||
| // See examples/reqwest_transport.rs for complete implementation | ||
| use eventsource_client::{HttpTransport, ResponseFuture}; | ||
|
|
||
| let mut client = es::ClientBuilder::for_url("https://example.com/stream")? | ||
| .header("Authorization", "Basic username:password")? | ||
| .build(); | ||
| struct ReqwestTransport { | ||
| client: reqwest::Client, | ||
| } | ||
|
|
||
| client | ||
| .stream() | ||
| .map_ok(|event| println!("got event: {:?}", event)) | ||
| .map_err(|err| eprintln!("error streaming events: {:?}", err)); | ||
| impl HttpTransport for ReqwestTransport { | ||
| fn request(&self, request: http::Request<()>) -> ResponseFuture { | ||
| // Convert request and call HTTP client | ||
| // See examples/ for full implementation | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| (Some boilerplate omitted for clarity; see [examples directory] for complete, | ||
| working code.) | ||
| ### 3. Use the client | ||
|
|
||
| ```rust | ||
| use eventsource_client::{ClientBuilder, SSE}; | ||
| use futures::TryStreamExt; | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| // Create HTTP transport | ||
| let transport = ReqwestTransport::new()?; | ||
|
|
||
| // Build SSE client | ||
| let client = ClientBuilder::for_url("https://example.com/stream")? | ||
| .header("Authorization", "Bearer token")? | ||
| .build_with_transport(transport); | ||
|
|
||
| // Stream events | ||
| let mut stream = client.stream(); | ||
|
|
||
| while let Some(event) = stream.try_next().await? { | ||
| match event { | ||
| SSE::Event(evt) => println!("Event: {}", evt.event_type), | ||
| SSE::Comment(c) => println!("Comment: {}", c), | ||
| SSE::Connected(_) => println!("Connected!"), | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| ``` | ||
|
|
||
| [examples directory]: https://github.com/launchdarkly/rust-eventsource-client/tree/main/eventsource-client/examples | ||
| ## Features | ||
|
|
||
| * tokio-based streaming client. | ||
| * Supports setting custom headers on the HTTP request (e.g. for endpoints | ||
| requiring authorization). | ||
| * Retry for failed connections. | ||
| * Reconnection if connection is interrupted, with exponential backoff. | ||
| * **Pluggable HTTP transport** - Use any HTTP client (hyper, reqwest, or custom) | ||
| * **Tokio-based streaming** - Efficient async/await support | ||
| * **Custom headers** - Full control over HTTP requests | ||
| * **Automatic reconnection** - Configurable exponential backoff | ||
| * **Retry logic** - Handle transient failures gracefully | ||
| * **Redirect following** - Automatic handling of HTTP redirects | ||
| * **Last-Event-ID** - Resume streams from last received event | ||
|
|
||
| ## Migration from v0.16 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I change this later from migration guide to just examples. |
||
|
|
||
| If you're upgrading from v0.16 (which used hyper 0.14 internally), see [MIGRATION.md](MIGRATION.md) for a detailed migration guide. | ||
|
|
||
| Key changes: | ||
| - You must now provide an HTTP transport implementation | ||
| - Removed `build()`, `build_http()`, and other hyper-specific methods | ||
| - Use `build_with_transport(transport)` instead | ||
| - Timeout configuration moved to your HTTP transport | ||
|
|
||
| ## Why Pluggable Transport? | ||
|
|
||
| 1. **Use latest HTTP clients** - Not locked to a specific HTTP library version | ||
| 2. **Full control** - Configure timeouts, TLS, proxies, etc. exactly as needed | ||
| 3. **Smaller library** - Focused on SSE protocol, not HTTP implementation | ||
| 4. **Flexibility** - Swap HTTP clients without changing SSE code | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| ┌─────────────────────────────────────┐ | ||
| │ Your Application │ | ||
| └─────────────┬───────────────────────┘ | ||
| │ | ||
| ▼ | ||
| ┌─────────────────────────────────────┐ | ||
| │ eventsource-client │ | ||
| │ (SSE Protocol Implementation) │ | ||
| └─────────────┬───────────────────────┘ | ||
| │ HttpTransport trait | ||
| ▼ | ||
| ┌─────────────────────────────────────┐ | ||
| │ Your HTTP Client │ | ||
| │ (hyper, reqwest, custom, etc.) │ | ||
| └─────────────────────────────────────┘ | ||
| ``` | ||
|
|
||
| ## Stability | ||
|
|
||
|
|
||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is temporary until we implement the hyper based version. But it keeps the tests passing without adding new dependencies.