Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions contract-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ launchdarkly-server-sdk = { path = "../launchdarkly-server-sdk/", default-featur
serde = { version = "1.0.132", features = ["derive"] }
serde_json = "1.0.73"
futures = "0.3.12"
hyper = { version = "0.14.19", features = ["client"] }
hyper-rustls = { version = "0.24.1" , optional = true, features = ["http2"]}
hyper-tls = { version = "0.5.0", optional = true }
hyper1-tls = { package = "hyper-tls", version = "0.6.0", optional = true }
hyper-util = { version = "0.1", features = ["client-legacy", "http1", "http2", "tokio"], optional = true }
hyper-util = { version = "0.1", features = ["client-legacy", "http1", "http2", "tokio"] }
hyper-rustls = { version = "0.27", default-features = false, features = ["http1", "http2", "native-tokio", "ring", "webpki-roots"], optional = true }
hyper-tls = { version = "0.6.0", optional = true }
reqwest = { version = "0.12.4", features = ["default", "blocking", "json"] }
async-mutex = "1.4.0"

[features]
default = ["rustls"]
rustls = ["hyper-rustls/http1", "hyper-rustls/http2", "launchdarkly-server-sdk/rustls", "hyper-util"]
tls = ["hyper-tls", "hyper1-tls", "hyper-util"]
rustls = ["hyper-rustls", "launchdarkly-server-sdk/rustls"]
tls = ["hyper-tls"]
2 changes: 1 addition & 1 deletion contract-tests/src/client_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl ClientEntity {
)),
}
}
command => Err(format!("Invalid command requested: {}", command)),
command => Err(format!("Invalid command requested: {command}")),
}
}

Expand Down
12 changes: 6 additions & 6 deletions contract-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder, Resu
use async_mutex::Mutex;
use client_entity::ClientEntity;
use futures::executor;
use hyper::client::HttpConnector;
use hyper_util::client::legacy::connect::HttpConnector;
use launchdarkly_server_sdk::Reference;
use serde::{self, Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -137,7 +137,7 @@ async fn create_client(
.await
{
Ok(ce) => ce,
Err(e) => return HttpResponse::InternalServerError().body(format!("{}", e)),
Err(e) => return HttpResponse::InternalServerError().body(format!("{e}")),
};

let mut counter = app_state.counter.lock().await;
Expand Down Expand Up @@ -218,8 +218,7 @@ type StreamingHttpsConnector = hyper_util::client::legacy::connect::HttpConnecto
#[cfg(feature = "tls")]
type HttpsConnector = hyper_tls::HttpsConnector<HttpConnector>;
#[cfg(feature = "tls")]
type StreamingHttpsConnector =
hyper1_tls::HttpsConnector<hyper_util::client::legacy::connect::HttpConnector>;
type StreamingHttpsConnector = hyper_tls::HttpsConnector<HttpConnector>;

#[actix_web::main]
async fn main() -> std::io::Result<()> {
Expand All @@ -241,21 +240,22 @@ async fn main() -> std::io::Result<()> {
#[cfg(feature = "rustls")]
let connector = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.expect("Failed to load native root certificates")
.https_or_http()
.enable_http1()
.enable_http2()
.build();

#[cfg(feature = "tls")]
let streaming_https_connector = hyper1_tls::HttpsConnector::new();
let streaming_https_connector = hyper_tls::HttpsConnector::new();
#[cfg(feature = "tls")]
let connector = hyper_tls::HttpsConnector::new();

let state = web::Data::new(AppState {
counter: Mutex::new(0),
client_entities: Mutex::new(HashMap::new()),
https_connector: connector,
streaming_https_connector: streaming_https_connector,
streaming_https_connector,
});

let server = HttpServer::new(move || {
Expand Down
9 changes: 7 additions & 2 deletions launchdarkly-server-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ parking_lot = "0.12.0"
tokio-stream = { version = "0.1.8", features = ["sync"] }
moka = { version = "0.12.1", features = ["sync"] }
uuid = {version = "1.2.2", features = ["v4"] }
hyper = { version = "0.14.19", features = ["client", "http1", "http2", "tcp"] }
hyper-rustls = { version = "0.24.1" , optional = true}
http = "1.0"
bytes = "1.11"
hyper = { version = "1.0", features = ["client", "http1", "http2"] }
hyper-util = { version = "0.1", features = ["client-legacy", "http1", "http2", "tokio"] }
http-body-util = { version = "0.1" }
hyper-rustls = { version = "0.27", default-features = false, features = ["http1", "http2", "native-tokio", "ring", "webpki-roots"], optional = true}
tower = { version = "0.4" }
rand = "0.9"
flate2 = { version = "1.0.35", optional = true }
aws-lc-rs = "1.14.1"
Expand Down
2 changes: 1 addition & 1 deletion launchdarkly-server-sdk/examples/print_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() {
} else if let ["str", name] = bits {
str_flags.push(name.to_string());
} else if let [flag_type, _] = bits {
error!("Unsupported flag type {} in {}", flag_type, flag);
error!("Unsupported flag type {flag_type} in {flag}");
exit(2);
} else if let [name] = bits {
bool_flags.push(name.to_string());
Expand Down
39 changes: 9 additions & 30 deletions launchdarkly-server-sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,7 @@ impl Client {
}

let initialized = tokio::time::timeout(timeout, self.initialized_async_internal()).await;
match initialized {
Ok(result) => Some(result),
Err(_) => None,
}
initialized.ok()
}

async fn initialized_async_internal(&self) -> bool {
Expand Down Expand Up @@ -335,7 +332,7 @@ impl Client {
// broadcast channel, so sending on it would always result in an error.
if !self.offline && !self.daemon_mode {
if let Err(e) = self.shutdown_broadcast.send(()) {
error!("Failed to shutdown client appropriately: {}", e);
error!("Failed to shutdown client appropriately: {e}");
}
}

Expand Down Expand Up @@ -379,10 +376,7 @@ impl Client {
if let Some(b) = val.as_bool() {
b
} else {
warn!(
"bool_variation called for a non-bool flag {:?} (got {:?})",
flag_key, val
);
warn!("bool_variation called for a non-bool flag {flag_key:?} (got {val:?})");
default
}
}
Expand All @@ -399,10 +393,7 @@ impl Client {
if let Some(s) = val.as_string() {
s
} else {
warn!(
"str_variation called for a non-string flag {:?} (got {:?})",
flag_key, val
);
warn!("str_variation called for a non-string flag {flag_key:?} (got {val:?})");
default
}
}
Expand All @@ -419,10 +410,7 @@ impl Client {
if let Some(f) = val.as_float() {
f
} else {
warn!(
"float_variation called for a non-float flag {:?} (got {:?})",
flag_key, val
);
warn!("float_variation called for a non-float flag {flag_key:?} (got {val:?})");
default
}
}
Expand All @@ -439,10 +427,7 @@ impl Client {
if let Some(f) = val.as_int() {
f
} else {
warn!(
"int_variation called for a non-int flag {:?} (got {:?})",
flag_key, val
);
warn!("int_variation called for a non-int flag {flag_key:?} (got {val:?})");
default
}
}
Expand Down Expand Up @@ -760,16 +745,10 @@ impl Client {
self.events_default.event_factory.new_migration_op(event),
);
}
Err(e) => error!(
"Failed to build migration event, no event will be sent: {}",
e
),
Err(e) => error!("Failed to build migration event, no event will be sent: {e}"),
}
}
Err(e) => error!(
"Failed to lock migration tracker, no event will be sent: {}",
e
),
Err(e) => error!("Failed to lock migration tracker, no event will be sent: {e}"),
}
}

Expand Down Expand Up @@ -849,7 +828,7 @@ mod tests {
use crossbeam_channel::Receiver;
use eval::{ContextBuilder, MultiContextBuilder};
use futures::FutureExt;
use hyper::client::HttpConnector;
use hyper_util::client::legacy::connect::HttpConnector;
use launchdarkly_server_sdk_evaluation::{Flag, Reason, Segment};
use maplit::hashmap;
use std::collections::HashMap;
Expand Down
6 changes: 4 additions & 2 deletions launchdarkly-server-sdk/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl ApplicationInfo {
match tag.is_valid() {
Ok(_) => self.tags.push(tag),
Err(e) => {
warn!("{}", e)
warn!("{e}")
}
}

Expand Down Expand Up @@ -322,7 +322,9 @@ impl ConfigBuilder {
Some(builder) => Ok(builder),
#[cfg(feature = "rustls")]
None => Ok(Box::new(EventProcessorBuilder::<
hyper_rustls::HttpsConnector<hyper::client::HttpConnector>,
hyper_rustls::HttpsConnector<
hyper_util::client::legacy::connect::HttpConnector,
>,
>::new())),
#[cfg(not(feature = "rustls"))]
None => Err(BuildError::InvalidConfig(
Expand Down
14 changes: 7 additions & 7 deletions launchdarkly-server-sdk/src/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl StreamingDataSource {
tags: &Option<String>,
transport: T,
) -> std::result::Result<Self, es::Error> {
let stream_url = format!("{}/all", base_url);
let stream_url = format!("{base_url}/all");

let client_builder = ClientBuilder::for_url(&stream_url)?;
let mut client_builder = client_builder
Expand Down Expand Up @@ -126,7 +126,7 @@ impl DataSource for StreamingDataSource {
continue;
},
es::SSE::Comment(str)=> {
debug!("data source got a comment: {}", str);
debug!("data source got a comment: {str}");
continue;
},
es::SSE::Event(ev) => ev,
Expand All @@ -147,7 +147,7 @@ impl DataSource for StreamingDataSource {
continue;
}
_ => {
error!("unhandled error on event stream: {:?}", e);
error!("unhandled error on event stream: {e:?}");
break;
}
}
Expand All @@ -171,7 +171,7 @@ impl DataSource for StreamingDataSource {
};
if let Err(e) = stored {
init_success = false;
error!("error processing update: {:?}", e);
error!("error processing update: {e:?}");
}

notify_init.call_once(|| (init_complete)(init_success));
Expand Down Expand Up @@ -213,12 +213,12 @@ impl DataSource for PollingDataSource {
Ok(factory) => match factory.build(self.tags.clone()) {
Ok(requester) => requester,
Err(e) => {
error!("{:?}", e);
error!("{e:?}");
return;
}
},
Err(e) => {
error!("{:?}", e);
error!("{e:?}");
return;
}
};
Expand Down Expand Up @@ -366,7 +366,7 @@ mod tests {
time::Duration,
};

use hyper::client::HttpConnector;
use hyper_util::client::legacy::connect::HttpConnector;
use mockito::Matcher;
use parking_lot::RwLock;
use test_case::test_case;
Expand Down
23 changes: 15 additions & 8 deletions launchdarkly-server-sdk/src/data_source_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use super::service_endpoints;
use crate::data_source::{DataSource, NullDataSource, PollingDataSource, StreamingDataSource};
use crate::feature_requester_builders::{FeatureRequesterFactory, HyperFeatureRequesterBuilder};
use eventsource_client as es;
use hyper::{client::connect::Connection, service::Service, Uri};
use http::Uri;
#[cfg(feature = "rustls")]
use hyper_rustls::HttpsConnectorBuilder;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use thiserror::Error;
use tokio::io::{AsyncRead, AsyncWrite};

#[cfg(test)]
use super::data_source;
Expand Down Expand Up @@ -115,7 +114,7 @@ impl<T: es::HttpTransport> DataSourceFactory for StreamingDataSourceBuilder<T> {
)),
};
let data_source = data_source_result?
.map_err(|e| BuildError::InvalidConfig(format!("invalid stream_base_url: {:?}", e)))?;
.map_err(|e| BuildError::InvalidConfig(format!("invalid stream_base_url: {e:?}")))?;
Ok(Arc::new(data_source))
}

Expand Down Expand Up @@ -176,7 +175,7 @@ impl Default for NullDataSourceBuilder {
/// ```
/// # use launchdarkly_server_sdk::{PollingDataSourceBuilder, ConfigBuilder};
/// # use hyper_rustls::HttpsConnector;
/// # use hyper::client::HttpConnector;
/// # use hyper_util::client::legacy::connect::HttpConnector;
/// # use std::time::Duration;
/// # fn main() {
/// ConfigBuilder::new("sdk-key").data_source(PollingDataSourceBuilder::<HttpsConnector<HttpConnector>>::new()
Expand Down Expand Up @@ -207,7 +206,7 @@ pub struct PollingDataSourceBuilder<C> {
/// # use launchdarkly_server_sdk::{PollingDataSourceBuilder, ConfigBuilder};
/// # use std::time::Duration;
/// # use hyper_rustls::HttpsConnector;
/// # use hyper::client::HttpConnector;
/// # use hyper_util::client::legacy::connect::HttpConnector;
/// # fn main() {
/// ConfigBuilder::new("sdk-key").data_source(PollingDataSourceBuilder::<HttpsConnector<HttpConnector>>::new()
/// .poll_interval(Duration::from_secs(60)));
Expand Down Expand Up @@ -243,8 +242,12 @@ impl<C> PollingDataSourceBuilder<C> {

impl<C> DataSourceFactory for PollingDataSourceBuilder<C>
where
C: Service<Uri> + Clone + Send + Sync + 'static,
C::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin,
C: tower::Service<Uri> + Clone + Send + Sync + 'static,
C::Response: hyper_util::client::legacy::connect::Connection
+ hyper::rt::Read
+ hyper::rt::Write
+ Send
+ Unpin,
C::Future: Send + Unpin + 'static,
C::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Expand All @@ -260,6 +263,10 @@ where
None => {
let connector = HttpsConnectorBuilder::new()
.with_native_roots()
.unwrap_or_else(|_| {
log::debug!("Falling back to webpki roots for polling HTTPS connector");
HttpsConnectorBuilder::new().with_webpki_roots()
})
.https_or_http()
.enable_http1()
.enable_http2()
Expand Down Expand Up @@ -342,7 +349,7 @@ impl DataSourceFactory for MockDataSourceBuilder {
#[cfg(test)]
mod tests {
use eventsource_client::{HyperTransport, ResponseFuture};
use hyper::client::HttpConnector;
use hyper_util::client::legacy::connect::HttpConnector;

use super::*;

Expand Down
Loading