launchdarkly / rust-server-sdk

LaunchDarkly Server-Side SDK for Rust
https://docs.launchdarkly.com/sdk/server-side/rust
Other
18 stars 13 forks source link

Support for http_proxy #88

Open butlerx opened 3 months ago

butlerx commented 3 months ago

Is your feature request related to a problem? Please describe.

We use an HTTP Proxy (squid) to connect to the internet. In the LD SDKs for other languages, we only have to specify HTTP_PROXY=http://proxy.internal:8080 to tell the SDK to connect to the internet via the proxy. This isn't supported in Rust though

Describe the solution you'd like When HTTP_PROXY is defined in the environment the LD client would use the proxy to connect to the ld backend

Current workaround

use hyper::client::HttpConnector;
use hyper_proxy::{Intercept, Proxy, ProxyConnector};
use launchdarkly_server_sdk::{
    Client, ConfigBuilder, EventProcessorBuilder, ServiceEndpointsBuilder,
    StreamingDataSourceBuilder,
};
pub use launchdarkly_server_sdk::{Context, ContextBuilder};
.....
    let ld_config = if let Ok(http_proxy) = std::env::var("HTTP_PROXY") {
        let proxy_uri = http_proxy.parse()?;
        let proxy = Proxy::new(Intercept::All, proxy_uri);
        let connector = HttpConnector::new();
        let proxy_connector = ProxyConnector::from_proxy(connector, proxy).unwrap();
        let mut data_source_builder = StreamingDataSourceBuilder::default();
        data_source_builder.https_connector(proxy_connector.clone());
        let mut event_processor_builder = EventProcessorBuilder::default();
        event_processor_builder.https_connector(proxy_connector);
        ConfigBuilder::new(&ld_sdk_key)
            .event_processor(&event_processor_builder)
            .data_source(&data_source_builder)
            .build()
    } else {
        ConfigBuilder::new(&ld_sdk_key).build()
    };
keelerm84 commented 2 months ago

Thank you for filing this request. I cannot provide a timeline given competing priorities and timelines, but we are tracking this request internally and will notify you once we have added support.

Internal ticket number sc-249422.