From 589fd2528648283fc7dd7cda936dcda178fe2dfd Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 3 May 2023 19:04:50 +0200 Subject: [PATCH] fix lint --- Cargo.lock | 1 + Cargo.toml | 1 + src/utils.rs | 20 +++++++------------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b21f48d..8ad5e17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1745,6 +1745,7 @@ dependencies = [ "axum", "chrono", "kuchiki", + "once_cell", "readable-readability", "reqwest", "shuttle-axum", diff --git a/Cargo.toml b/Cargo.toml index 0fd9f8a..1d9057b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,5 @@ chrono = "0.4.24" kuchiki = "0.8.1" shuttle-axum = { version = "0.15.0" } shuttle-runtime = { version = "0.15.0" } +once_cell = "1.17.1" diff --git a/src/utils.rs b/src/utils.rs index 8e05a98..5d8daab 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,25 +1,19 @@ -use axum::{ - extract::TypedHeader, - headers::UserAgent -}; +use axum::{extract::TypedHeader, headers::UserAgent}; +use once_cell::sync::Lazy; use reqwest::header::HeaderValue; - -const DEFAULT_USER_AGENT: HeaderValue = HeaderValue::from_static( - concat!("Readable/", env!("CARGO_PKG_VERSION")) -); - +static DEFAULT_USER_AGENT: Lazy = + Lazy::new(|| HeaderValue::from_static(concat!("Readable/", env!("CARGO_PKG_VERSION")))); pub fn forwarded_agent(ua_header: &Option>) -> HeaderValue { match ua_header { Some(TypedHeader(ua)) => { - HeaderValue::from_str(ua.as_str()).unwrap_or(DEFAULT_USER_AGENT) - }, - None => DEFAULT_USER_AGENT, + HeaderValue::from_str(ua.as_str()).unwrap_or_else(|_| DEFAULT_USER_AGENT.clone()) + } + None => DEFAULT_USER_AGENT.clone(), } } - /// get current date and time as UTC /// and format as: 1 December, 2017 12:00:00 pub fn get_time() -> String {