From 3e3c30d7f18a3951eedaffa0eb43be096c9ec95c Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Tue, 26 Dec 2023 16:24:53 -0500 Subject: [PATCH] Update cookie + changes --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/server.rs | 6 +++--- src/settings.rs | 8 ++++---- src/subreddit.rs | 12 ++++++------ src/utils.rs | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4312abe..588c540 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -294,9 +294,9 @@ checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "cookie" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7efb37c3e1ccb1ff97164ad95ac1606e8ccd35b3fa0a7d99a304c7f4a428cc24" +checksum = "3cd91cf61412820176e137621345ee43b3f4423e589e7ae4e50d601d93e35ef8" dependencies = [ "time", "version_check", diff --git a/Cargo.toml b/Cargo.toml index eb6ca26..284d974 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ cached = { version = "0.46.1", features = ["async"] } clap = { version = "4.4.11", default-features = false, features = ["std", "env"] } regex = "1.10.2" serde = { version = "1.0.193", features = ["derive"] } -cookie = "0.17.0" +cookie = "0.18.0" futures-lite = "1.12.0" hyper = { version = "0.14.23", features = ["full"] } hyper-rustls = "0.24.0" diff --git a/src/server.rs b/src/server.rs index 9db7cba..20e48ea 100644 --- a/src/server.rs +++ b/src/server.rs @@ -138,7 +138,7 @@ impl RequestExt for Request { .to_str() .unwrap_or_default() .split("; ") - .map(|cookie| Cookie::parse(cookie).unwrap_or_else(|_| Cookie::named(""))) + .map(|cookie| Cookie::parse(cookie).unwrap_or_else(|_| Cookie::from(""))) .collect() }) } @@ -155,7 +155,7 @@ impl ResponseExt for Response { .to_str() .unwrap_or_default() .split("; ") - .map(|cookie| Cookie::parse(cookie).unwrap_or_else(|_| Cookie::named(""))) + .map(|cookie| Cookie::parse(cookie).unwrap_or_else(|_| Cookie::from(""))) .collect() }) } @@ -167,7 +167,7 @@ impl ResponseExt for Response { } fn remove_cookie(&mut self, name: String) { - let mut cookie = Cookie::named(name); + let mut cookie = Cookie::from(name); cookie.set_path("/"); cookie.set_max_age(Duration::seconds(1)); if let Ok(val) = header::HeaderValue::from_str(&cookie.to_string()) { diff --git a/src/settings.rs b/src/settings.rs index 6f3803d..55bf5b9 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -78,11 +78,11 @@ pub async fn set(req: Request) -> Result, String> { for &name in &PREFS { match form.get(name) { Some(value) => response.insert_cookie( - Cookie::build(name.to_owned(), value.clone()) + Cookie::build((name.to_owned(), value.clone())) .path("/") .http_only(true) .expires(OffsetDateTime::now_utc() + Duration::weeks(52)) - .finish(), + .into(), ), None => response.remove_cookie(name.to_string()), }; @@ -117,11 +117,11 @@ fn set_cookies_method(req: Request, remove_cookies: bool) -> Response response.insert_cookie( - Cookie::build(name.to_owned(), value.clone()) + Cookie::build((name.to_owned(), value.clone())) .path("/") .http_only(true) .expires(OffsetDateTime::now_utc() + Duration::weeks(52)) - .finish(), + .into(), ), None => { if remove_cookies { diff --git a/src/subreddit.rs b/src/subreddit.rs index 6ebf523..6dc91f4 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -177,11 +177,11 @@ pub async fn add_quarantine_exception(req: Request) -> Result) -> Result, response.remove_cookie("subscriptions".to_string()); } else { response.insert_cookie( - Cookie::build("subscriptions", sub_list.join("+")) + Cookie::build(("subscriptions", sub_list.join("+"))) .path("/") .http_only(true) .expires(OffsetDateTime::now_utc() + Duration::weeks(52)) - .finish(), + .into(), ); } if filters.is_empty() { response.remove_cookie("filters".to_string()); } else { response.insert_cookie( - Cookie::build("filters", filters.join("+")) + Cookie::build(("filters", filters.join("+"))) .path("/") .http_only(true) .expires(OffsetDateTime::now_utc() + Duration::weeks(52)) - .finish(), + .into(), ); } diff --git a/src/utils.rs b/src/utils.rs index b8084ba..8455636 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -769,7 +769,7 @@ pub fn setting(req: &Request, name: &str) -> String { if let Some(default) = crate::config::get_setting(&format!("LIBREDDIT_DEFAULT_{}", name.to_uppercase())) { Cookie::new(name, default) } else { - Cookie::named(name) + Cookie::from(name) } }) .value()