Skip to content

Commit

Permalink
Apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
threema-donat committed May 14, 2024
1 parent f36f925 commit 8c43866
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum PushRelayError {
#[error("Reqwest error: {0}")]
Reqwest(#[from] ReqwestError),

#[error("{reason}: {source}")]
#[error("I/O error: {reason}: {source}")]
IoError {
reason: &'static str,
source: std::io::Error,
Expand Down
6 changes: 3 additions & 3 deletions src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use reqwest::{Client, Error};
/// Create a HTTP 1 client instance.
///
/// Parameter: Timeout for idle sockets being kept-alive
pub fn make_client(pool_idle_timeout_seconds: u64) -> Result<Client, Error> {
pub fn make_client(pool_idle_timeout_seconds: u64, https_only: bool) -> Result<Client, Error> {
Client::builder()
.pool_idle_timeout(Duration::from_secs(pool_idle_timeout_seconds))
.http1_only()
.use_rustls_tls()
.https_only(false)
.tls_built_in_root_certs(true)
.https_only(if cfg!(test) { false } else { https_only })
.tls_built_in_native_certs(true)
.build()
}
7 changes: 2 additions & 5 deletions src/influxdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Influxdb {
) -> Result<Self, String> {
// Initialize HTTP client
let client =
make_client(90).map_err(|e| format!("Failed to initialize http client: {e}"))?;
make_client(90, false).map_err(|e| format!("Failed to initialize http client: {e}"))?;

// Determine hostname
let hostname = hostname::get().ok().map_or_else(
Expand Down Expand Up @@ -92,10 +92,7 @@ impl Influxdb {
}
}

async fn log<B>(&self, body: B) -> InfluxdbResult
where
B: Into<Body>,
{
async fn log(&self, body: impl Into<Body>) -> InfluxdbResult {
let body: Body = body.into();

// Send request
Expand Down
4 changes: 2 additions & 2 deletions src/push/hms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct HmsStateConfig {
type SharedHmsConfig = Arc<HmsStateConfig>;

impl HmsStateConfig {
pub fn new() -> SharedHmsConfig {
pub fn new_shared() -> SharedHmsConfig {
let login_endpoint = Cow::Borrowed("https://oauth-login.cloud.huawei.com");
let push_endpoint = Cow::Borrowed("https://push-api.cloud.huawei.com");
Arc::new(Self {
Expand Down Expand Up @@ -543,7 +543,7 @@ mod tests {
const CLIENT_SECRET: &str = "sehr-sekur";

// Set up context
let client = http_client::make_client(10).unwrap();
let client = http_client::make_client(10, true).unwrap();
let context = HmsContext::new(
client,
HmsConfig {
Expand Down
13 changes: 7 additions & 6 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn serve(
let hms = hms.unwrap_or_default();

// Create FCM HTTP client
let fcm_client = http_client::make_client(90)?;
let fcm_client = http_client::make_client(90, true)?;

// Create APNs clients
let apns_client_prod = apns::create_client(
Expand All @@ -85,7 +85,7 @@ pub async fn serve(
apns::create_client(Endpoint::Sandbox, apns_api_key, apns.team_id, apns.key_id)?;

// Create a shared HMS HTTP client
let hms_client = http_client::make_client(90)?;
let hms_client = http_client::make_client(90, true)?;

// Create a HMS context for every config entry
let hms_contexts = Arc::new(
Expand All @@ -100,7 +100,7 @@ pub async fn serve(
);

// Create Threema Gateway HTTP client
let threema_gateway_client = http_client::make_client(90)?;
let threema_gateway_client = http_client::make_client(90, true)?;

// Create InfluxDB client
let influxdb = influxdb.map(|c| {
Expand Down Expand Up @@ -141,7 +141,7 @@ pub async fn serve(
apns_client_prod: apns_client_prod.clone(),
apns_client_sbox: apns_client_sbox.clone(),
hms_contexts: hms_contexts.clone(),
hms_config: HmsStateConfig::new(),
hms_config: HmsStateConfig::new_shared(),
threema_gateway_client: threema_gateway_client.clone(),
threema_gateway_private_key: threema_gateway_private_key.clone(),
threema_gateway_config: threema_gateway.clone(),
Expand Down Expand Up @@ -540,7 +540,7 @@ mod tests {
}

fn get_test_state(fcm_endpoint: Option<String>) -> AppState {
let fcm_client = http_client::make_client(10).expect("fcm_client");
let fcm_client = http_client::make_client(10, true).expect("fcm_client");
let api_key = get_apns_test_key();
let apns_client_prod = apns::create_client(
Endpoint::Production,
Expand All @@ -552,7 +552,8 @@ mod tests {
let apns_client_sbox =
apns::create_client(Endpoint::Sandbox, api_key.as_slice(), "team_id", "key_id")
.unwrap();
let threema_gateway_client = http_client::make_client(10).expect("threema_gateway_client");
let threema_gateway_client =
http_client::make_client(10, true).expect("threema_gateway_client");
AppState {
fcm_client,
fcm_config: FcmStateConfig::stub_with(fcm_endpoint),
Expand Down

0 comments on commit 8c43866

Please sign in to comment.