launchdarkly_sdk_transport/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! Generic HTTP transport trait for LaunchDarkly Rust libraries.
4//!
5//! This crate provides the [`transport::HttpTransport`] trait, which abstracts over HTTP client
6//! implementations. This allows LaunchDarkly SDKs to work with different HTTP clients (hyper,
7//! reqwest, or custom implementations) without being tightly coupled to any specific one.
8//!
9//! # Why Use This Crate?
10//!
11//! LaunchDarkly SDKs need to make HTTP requests for various purposes:
12//! - Streaming feature flag updates via Server-Sent Events (SSE)
13//! - Polling for flag data
14//! - Sending analytics events
15//!
16//! Rather than forcing users to depend on a specific HTTP client, this crate provides a trait
17//! that users can implement with their preferred HTTP library. This is especially useful when:
18//! - You already use a specific HTTP client in your application
19//! - You need custom networking behavior (proxies, custom TLS, etc.)
20//! - You want to minimize dependencies
21//!
22//! # Core Components
23//!
24//! - [`transport::HttpTransport`] - The main trait to implement for custom HTTP clients
25//! - [`transport::TransportError`] - Error type for transport operations
26//! - [`transport::ByteStream`] - Type alias for streaming response bodies
27//! - Re-exported types from the `http` crate for convenience
28//!
29//! # Built-in Implementations
30//!
31//! This crate provides an optional hyper v1 transport implementation via feature flags:
32//!
33//! - **`hyper` feature**: HTTP-only transport using hyper v1
34//! - Includes proxy support, timeouts, HTTP/1 and HTTP/2
35//! - Suitable for plain HTTP or when TLS is handled elsewhere
36//!
37//! - **`hyper-rustls-native-roots` feature**: Full HTTPS transport using hyper-rustls and native
38//! certificates.
39//!
40//! - **`hyper-rustls-webpki-roots` feature**: Full HTTPS transport using hyper-rustls using
41//! Mozilla's bundled certificates.
42//!
43//! - **`native-tls` feature**: Full HTTPS transport using hyper-tls.
44//!
45//! See [`transport_hyper::HyperTransport`] for detailed documentation and examples.
46//!
47//! # Example Usage
48//!
49//! Implementing the trait for a custom HTTP client:
50//!
51//! ```no_run
52//! use launchdarkly_sdk_transport::{HttpTransport, ResponseFuture, ByteStream, TransportError};
53//! use bytes::Bytes;
54//! use http::{Request, Response};
55//!
56//! #[derive(Clone)]
57//! struct MyHttpClient {
58//! // Your HTTP client implementation
59//! }
60//!
61//! impl HttpTransport for MyHttpClient {
62//! fn request(&self, request: Request<Option<Bytes>>) -> ResponseFuture {
63//! Box::pin(async move {
64//! // Convert the http::Request to your client's format
65//! // Execute the request
66//! // Return http::Response<ByteStream>
67//! todo!("Implement your HTTP logic here")
68//! })
69//! }
70//! }
71//! ```
72//!
73//! Then pass your transport implementation to LaunchDarkly SDK configuration.
74
75pub mod transport;
76pub use transport::*;
77
78#[cfg(feature = "hyper")]
79#[cfg_attr(docsrs, doc(cfg(feature = "hyper")))]
80pub mod transport_hyper;
81#[cfg(feature = "hyper")]
82#[cfg_attr(docsrs, doc(cfg(feature = "hyper")))]
83pub use transport_hyper::*;