From f465394f9356204677647a9a4a58eb1360db22b3 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Sat, 25 Mar 2023 16:32:42 -0400 Subject: [PATCH] Address fmt + clippy --- src/client.rs | 19 +++++++++++++------ src/main.rs | 2 +- src/server.rs | 4 ++-- src/utils.rs | 30 +++++++++++++++--------------- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/client.rs b/src/client.rs index b1d15a6..4c174cd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,20 +1,20 @@ use cached::proc_macro::cached; use futures_lite::{future::Boxed, FutureExt}; -use hyper::{body, body::Buf, client, header, Body, Method, Request, Response, Uri, Client}; +use hyper::client::HttpConnector; +use hyper::{body, body::Buf, client, header, Body, Client, Method, Request, Response, Uri}; +use hyper_rustls::HttpsConnector; use libflate::gzip; +use once_cell::sync::Lazy; use percent_encoding::{percent_encode, CONTROLS}; use serde_json::Value; use std::{io, result::Result}; -use hyper::client::HttpConnector; -use hyper_rustls::HttpsConnector; -use once_cell::sync::Lazy; use crate::dbg_msg; use crate::server::RequestExt; const REDDIT_URL_BASE: &str = "https://www.reddit.com"; -static CLIENT: Lazy>> = Lazy::new(||{ +static CLIENT: Lazy>> = Lazy::new(|| { let https = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build(); client::Client::builder().build(https) }); @@ -142,7 +142,14 @@ fn request(method: &'static Method, path: String, redirect: bool, quarantine: bo .header("Accept-Encoding", if method == Method::GET { "gzip" } else { "identity" }) .header("Accept-Language", "en-US,en;q=0.5") .header("Connection", "keep-alive") - .header("Cookie", if quarantine { "_options=%7B%22pref_quarantine_optin%22%3A%20true%2C%20%22pref_gated_sr_optin%22%3A%20true%7D" } else { "" }) + .header( + "Cookie", + if quarantine { + "_options=%7B%22pref_quarantine_optin%22%3A%20true%2C%20%22pref_gated_sr_optin%22%3A%20true%7D" + } else { + "" + }, + ) .body(Body::empty()); async move { diff --git a/src/main.rs b/src/main.rs index 7489aa0..4f5d3d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -161,7 +161,7 @@ async fn main() { let mut app = server::Server::new(); // Force evaluation of statics. In instance_info case, we need to evaluate - // the timestamp so deploy date is accurate - in config case, we need to + // the timestamp so deploy date is accurate - in config case, we need to // evaluate the configuration to avoid paying penalty at first request. Lazy::force(&config::CONFIG); diff --git a/src/server.rs b/src/server.rs index 501b933..b1d293b 100644 --- a/src/server.rs +++ b/src/server.rs @@ -253,7 +253,7 @@ impl Server { .boxed() } // If there was a routing error - Err(e) => async move { new_boilerplate(def_headers, req_headers, 404, e.into()).await }.boxed(), + Err(e) => new_boilerplate(def_headers, req_headers, 404, e.into()).boxed(), } })) } @@ -379,7 +379,7 @@ fn determine_compressor(accept_encoding: String) -> Option { // This loop reads the requested compressors and keeps track of whichever // one has the highest priority per our heuristic. - for val in accept_encoding.to_string().split(',') { + for val in accept_encoding.split(',') { let mut q: f64 = 1.0; // The compressor and q-value (if the latter is defined) diff --git a/src/utils.rs b/src/utils.rs index a823ff5..4b47a08 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -530,21 +530,21 @@ impl Preferences { } Self { available_themes: themes, - theme: setting(&req, "theme"), - front_page: setting(&req, "front_page"), - layout: setting(&req, "layout"), - wide: setting(&req, "wide"), - show_nsfw: setting(&req, "show_nsfw"), - blur_nsfw: setting(&req, "blur_nsfw"), - use_hls: setting(&req, "use_hls"), - hide_hls_notification: setting(&req, "hide_hls_notification"), - autoplay_videos: setting(&req, "autoplay_videos"), - disable_visit_reddit_confirmation: setting(&req, "disable_visit_reddit_confirmation"), - comment_sort: setting(&req, "comment_sort"), - post_sort: setting(&req, "post_sort"), - subscriptions: setting(&req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), - filters: setting(&req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), - hide_awards: setting(&req, "hide_awards"), + theme: setting(req, "theme"), + front_page: setting(req, "front_page"), + layout: setting(req, "layout"), + wide: setting(req, "wide"), + show_nsfw: setting(req, "show_nsfw"), + blur_nsfw: setting(req, "blur_nsfw"), + use_hls: setting(req, "use_hls"), + hide_hls_notification: setting(req, "hide_hls_notification"), + autoplay_videos: setting(req, "autoplay_videos"), + disable_visit_reddit_confirmation: setting(req, "disable_visit_reddit_confirmation"), + comment_sort: setting(req, "comment_sort"), + post_sort: setting(req, "post_sort"), + subscriptions: setting(req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), + filters: setting(req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), + hide_awards: setting(req, "hide_awards"), } } }