Skip to main content

Crate launchdarkly_sdk_transport

Crate launchdarkly_sdk_transport 

Source
Expand description

Generic HTTP transport trait for LaunchDarkly Rust libraries.

This crate provides the transport::HttpTransport trait, which abstracts over HTTP client implementations. This allows LaunchDarkly SDKs to work with different HTTP clients (hyper, reqwest, or custom implementations) without being tightly coupled to any specific one.

§Why Use This Crate?

LaunchDarkly SDKs need to make HTTP requests for various purposes:

  • Streaming feature flag updates via Server-Sent Events (SSE)
  • Polling for flag data
  • Sending analytics events

Rather than forcing users to depend on a specific HTTP client, this crate provides a trait that users can implement with their preferred HTTP library. This is especially useful when:

  • You already use a specific HTTP client in your application
  • You need custom networking behavior (proxies, custom TLS, etc.)
  • You want to minimize dependencies

§Core Components

§Built-in Implementations

This crate provides an optional hyper v1 transport implementation via feature flags:

  • hyper feature: HTTP-only transport using hyper v1

    • Includes proxy support, timeouts, HTTP/1 and HTTP/2
    • Suitable for plain HTTP or when TLS is handled elsewhere
  • hyper-rustls-native-roots feature: Full HTTPS transport using hyper-rustls and native certificates.

  • hyper-rustls-webpki-roots feature: Full HTTPS transport using hyper-rustls using Mozilla’s bundled certificates.

  • native-tls feature: Full HTTPS transport using hyper-tls.

See transport_hyper::HyperTransport for detailed documentation and examples.

§Example Usage

Implementing the trait for a custom HTTP client:

use launchdarkly_sdk_transport::{HttpTransport, ResponseFuture, ByteStream, TransportError};
use bytes::Bytes;
use http::{Request, Response};

#[derive(Clone)]
struct MyHttpClient {
    // Your HTTP client implementation
}

impl HttpTransport for MyHttpClient {
    fn request(&self, request: Request<Option<Bytes>>) -> ResponseFuture {
        Box::pin(async move {
            // Convert the http::Request to your client's format
            // Execute the request
            // Return http::Response<ByteStream>
            todo!("Implement your HTTP logic here")
        })
    }
}

Then pass your transport implementation to LaunchDarkly SDK configuration.

Re-exports§

pub use transport::*;
pub use transport_hyper::*;

Modules§

transport
HTTP transport abstraction for LaunchDarkly SDKs.
transport_hyper
Hyper v1 transport implementation.