Skip to content

Commit 0027cac

Browse files
authored
feat: Replace local http transport with launchdarkly-sdk-transport (#118)
1 parent 491b5cf commit 0027cac

13 files changed

Lines changed: 67 additions & 996 deletions

File tree

.github/actions/build-docs/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ runs:
66
steps:
77
- name: Build Documentation
88
shell: bash
9-
run: cargo doc --no-deps -p eventsource-client
9+
run: cargo doc --no-deps --all-features -p eventsource-client

.github/actions/ci/action.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: CI Workflow
22
description: 'Shared CI workflow.'
33

4+
inputs:
5+
feature-flags:
6+
description: 'Cargo feature flags to pass to test and clippy commands'
7+
required: false
8+
default: ''
9+
410
runs:
511
using: composite
612
steps:
@@ -10,15 +16,15 @@ runs:
1016

1117
- name: Run tests
1218
shell: bash
13-
run: cargo test --all-features -p eventsource-client
19+
run: cargo test ${{ inputs.feature-flags }} -p eventsource-client
1420

1521
- name: Run slower integration tests
1622
shell: bash
17-
run: cargo test --all-features -p eventsource-client --lib -- --ignored
23+
run: cargo test ${{ inputs.feature-flags }} -p eventsource-client --lib -- --ignored
1824

1925
- name: Run clippy checks
2026
shell: bash
21-
run: cargo clippy --all-features -p eventsource-client -- -D warnings
27+
run: cargo clippy ${{ inputs.feature-flags }} -p eventsource-client -- -D warnings
2228

2329
- name: Build contract tests
2430
shell: bash

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ on:
1616
jobs:
1717
ci-build:
1818
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
features:
23+
- name: "default"
24+
flags: ""
25+
- name: "no-features"
26+
flags: "--no-default-features"
27+
- name: "hyper"
28+
flags: "--no-default-features --features hyper"
29+
- name: "hyper-rustls"
30+
flags: "--no-default-features --features hyper-rustls"
31+
32+
name: CI (${{ matrix.features.name }})
1933

2034
steps:
2135
- uses: actions/checkout@v4
@@ -32,4 +46,24 @@ jobs:
3246
rustup component add rustfmt clippy
3347
3448
- uses: ./.github/actions/ci
49+
with:
50+
feature-flags: ${{ matrix.features.flags }}
51+
52+
build-docs:
53+
runs-on: ubuntu-latest
54+
name: Build Documentation (all features)
55+
56+
steps:
57+
- uses: actions/checkout@v4
58+
with:
59+
fetch-depth: 0
60+
61+
- name: Get Rust version
62+
id: rust-version
63+
run: cat ./.github/variables/rust-versions.env >> $GITHUB_OUTPUT
64+
65+
- name: Setup rust tooling
66+
run: |
67+
rustup override set ${{ steps.rust-version.outputs.target }}
68+
3569
- uses: ./.github/actions/build-docs

contract-tests/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "Apache-2.0"
77
[dependencies]
88
futures = { version = "0.3.21" }
99
serde = { version = "1.0", features = ["derive"] }
10-
eventsource-client = { path = "../eventsource-client", features = ["hyper", "hyper-rustls"] }
10+
eventsource-client = { path = "../eventsource-client", features = ["hyper-rustls"] }
1111
serde_json = { version = "1.0.39"}
1212
actix = { version = "0.13.1"}
1313
actix-web = { version = "4"}
@@ -18,5 +18,7 @@ log = "0.4.6"
1818
http = "1.0"
1919
bytes = "1.5"
2020

21+
launchdarkly-sdk-transport = { git = "https://github.com/launchdarkly/rust-sdk-transport.git", branch = "main" }
22+
2123
[[bin]]
2224
name = "sse-test-api"

contract-tests/src/bin/sse-test-api/stream_entity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
};
88

99
use eventsource_client as es;
10-
use eventsource_client::HyperTransport;
10+
use launchdarkly_sdk_transport::HyperTransport;
1111

1212
use crate::{Config, EventType};
1313

eventsource-client/Cargo.toml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,7 @@ tokio = { version = "1.17.0", features = ["time"] }
2020
rand = "0.8.5"
2121
base64 = "0.22.1"
2222

23-
#
24-
# Dependencies for hyper transport
25-
#
26-
hyper = { version = "1.0", features = ["client", "http1", "http2"], optional = true }
27-
hyper-util = { version = "0.1", features = ["client-legacy", "http1", "http2", "tokio"], optional = true }
28-
http-body-util = { version = "0.1", optional = true }
29-
hyper-http-proxy = { version = "1.1.0", optional = true }
30-
hyper-rustls = { version = "0.27", default-features = false, features = ["http1", "http2", "native-tokio", "ring", "tls12", "webpki-roots"], optional = true }
31-
hyper-timeout = { version = "0.5", optional = true }
32-
tower = { version = "0.4", optional = true }
33-
no-proxy = { version = "0.3.6", default-features = false }
23+
launchdarkly-sdk-transport = { git = "https://github.com/launchdarkly/rust-sdk-transport.git", branch = "main" }
3424

3525
[dev-dependencies]
3626
env_logger = "0.10.0"
@@ -41,7 +31,11 @@ tokio = { version = "1.2.0", features = ["macros", "rt-multi-thread"] }
4131
test-case = "3.2.1"
4232
proptest = "1.0.0"
4333

34+
[[example]]
35+
name = "tail"
36+
required-features = ["hyper"]
37+
4438
[features]
4539
default = ["hyper"]
46-
hyper = ["dep:hyper", "dep:hyper-util", "dep:http-body-util", "dep:hyper-timeout", "dep:tower", "dep:hyper-http-proxy"]
47-
hyper-rustls = ["hyper", "dep:hyper-rustls"]
40+
hyper = ["launchdarkly-sdk-transport/hyper"]
41+
hyper-rustls = ["hyper", "launchdarkly-sdk-transport/hyper-rustls"]

eventsource-client/examples/tail.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use futures::{Stream, TryStreamExt};
1616
use std::{env, process, time::Duration};
1717

1818
use eventsource_client as es;
19+
use launchdarkly_sdk_transport::HyperTransport;
1920

2021
#[tokio::main]
2122
#[allow(clippy::result_large_err)]
@@ -56,7 +57,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5657
}
5758

5859
async fn run_with_http(url: &str, auth_header: &str) -> Result<(), Box<dyn std::error::Error>> {
59-
let transport = es::HyperTransport::builder()
60+
let transport = HyperTransport::builder()
6061
.connect_timeout(Duration::from_secs(10))
6162
.read_timeout(Duration::from_secs(30))
6263
.build_http()?;
@@ -82,7 +83,7 @@ async fn run_with_http(url: &str, auth_header: &str) -> Result<(), Box<dyn std::
8283

8384
#[cfg(feature = "hyper-rustls")]
8485
async fn run_with_https(url: &str, auth_header: &str) -> Result<(), Box<dyn std::error::Error>> {
85-
let transport = es::HyperTransport::builder()
86+
let transport = HyperTransport::builder()
8687
.connect_timeout(Duration::from_secs(10))
8788
.read_timeout(Duration::from_secs(30))
8889
.build_https()?;

eventsource-client/src/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ use tokio::time::Sleep;
2121
use crate::{
2222
config::ReconnectOptions,
2323
response::{ErrorBody, Response},
24-
{ByteStream, HttpTransport, ResponseFuture},
2524
};
2625
use crate::{
2726
error::{Error, Result},
2827
event_parser::ConnectionDetails,
2928
};
29+
use launchdarkly_sdk_transport::{ByteStream, HttpTransport, ResponseFuture};
3030

3131
use crate::event_parser::EventParser;
3232
use crate::event_parser::SSE;
@@ -313,7 +313,7 @@ impl<T: HttpTransport> ReconnectingRequest<T> {
313313
// Include the request body if set. Most SSE requests use GET and will have None,
314314
// but some implementations (e.g., using REPORT method) may include a body.
315315
let request = request_builder
316-
.body(self.props.body.clone())
316+
.body(self.props.body.clone().map(|b| b.into()))
317317
.map_err(|e| Error::InvalidParameter(Box::new(e)))?;
318318

319319
Ok(self.transport.request(request))
@@ -573,7 +573,7 @@ fn delay(dur: Duration, description: &str) -> Sleep {
573573

574574
mod private {
575575
use crate::client::ClientImpl;
576-
use crate::HttpTransport;
576+
use launchdarkly_sdk_transport::HttpTransport;
577577

578578
pub trait Sealed {}
579579
impl<T: HttpTransport> Sealed for ClientImpl<T> {}
@@ -618,8 +618,8 @@ mod tests {
618618
use crate::{
619619
client::{RequestProps, State},
620620
ReconnectOptionsBuilder, ReconnectingRequest,
621-
{ByteStream, HttpTransport, ResponseFuture, TransportError},
622621
};
622+
use launchdarkly_sdk_transport::{ByteStream, HttpTransport, ResponseFuture, TransportError};
623623

624624
// Mock transport for testing
625625
#[derive(Clone)]
@@ -634,7 +634,7 @@ mod tests {
634634
}
635635

636636
impl HttpTransport for MockTransport {
637-
fn request(&self, _request: http::Request<Option<String>>) -> ResponseFuture {
637+
fn request(&self, _request: http::Request<Option<Bytes>>) -> ResponseFuture {
638638
if self.fail_request {
639639
// Simulate a connection error
640640
Box::pin(async {

eventsource-client/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::response::{ErrorBody, Response};
2-
use crate::TransportError;
2+
use launchdarkly_sdk_transport::TransportError;
33

44
/// Error type for invalid response headers encountered in ResponseDetails.
55
#[derive(Debug)]

eventsource-client/src/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
//!
1515
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
1616
//! // You need to implement HttpTransport trait for your HTTP client
17-
//! // See examples/hyper_transport.rs or examples/reqwest_transport.rs for reference implementations
1817
//! # struct MyTransport;
19-
//! # impl eventsource_client::HttpTransport for MyTransport {
18+
//! # impl launchdarkly_sdk_transport::HttpTransport for MyTransport {
2019
//! # fn request(&self, _req: http::Request<Option<String>>) -> eventsource_client::ResponseFuture {
2120
//! # unimplemented!()
2221
//! # }
@@ -56,17 +55,10 @@ mod error;
5655
mod event_parser;
5756
mod response;
5857
mod retry;
59-
mod transport;
60-
61-
#[cfg(feature = "hyper")]
62-
mod transport_hyper;
6358

6459
pub use client::*;
6560
pub use config::*;
6661
pub use error::*;
6762
pub use event_parser::Event;
6863
pub use event_parser::SSE;
6964
pub use response::Response;
70-
pub use transport::*;
71-
#[cfg(feature = "hyper")]
72-
pub use transport_hyper::*;

0 commit comments

Comments
 (0)