Update cookie + changes

This commit is contained in:
Matthew Esposito 2023-12-26 16:24:53 -05:00
parent e82c3fbea0
commit 3e3c30d7f1
No known key found for this signature in database
6 changed files with 17 additions and 17 deletions

4
Cargo.lock generated
View File

@ -294,9 +294,9 @@ checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]] [[package]]
name = "cookie" name = "cookie"
version = "0.17.0" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7efb37c3e1ccb1ff97164ad95ac1606e8ccd35b3fa0a7d99a304c7f4a428cc24" checksum = "3cd91cf61412820176e137621345ee43b3f4423e589e7ae4e50d601d93e35ef8"
dependencies = [ dependencies = [
"time", "time",
"version_check", "version_check",

View File

@ -13,7 +13,7 @@ cached = { version = "0.46.1", features = ["async"] }
clap = { version = "4.4.11", default-features = false, features = ["std", "env"] } clap = { version = "4.4.11", default-features = false, features = ["std", "env"] }
regex = "1.10.2" regex = "1.10.2"
serde = { version = "1.0.193", features = ["derive"] } serde = { version = "1.0.193", features = ["derive"] }
cookie = "0.17.0" cookie = "0.18.0"
futures-lite = "1.12.0" futures-lite = "1.12.0"
hyper = { version = "0.14.23", features = ["full"] } hyper = { version = "0.14.23", features = ["full"] }
hyper-rustls = "0.24.0" hyper-rustls = "0.24.0"

View File

@ -138,7 +138,7 @@ impl RequestExt for Request<Body> {
.to_str() .to_str()
.unwrap_or_default() .unwrap_or_default()
.split("; ") .split("; ")
.map(|cookie| Cookie::parse(cookie).unwrap_or_else(|_| Cookie::named(""))) .map(|cookie| Cookie::parse(cookie).unwrap_or_else(|_| Cookie::from("")))
.collect() .collect()
}) })
} }
@ -155,7 +155,7 @@ impl ResponseExt for Response<Body> {
.to_str() .to_str()
.unwrap_or_default() .unwrap_or_default()
.split("; ") .split("; ")
.map(|cookie| Cookie::parse(cookie).unwrap_or_else(|_| Cookie::named(""))) .map(|cookie| Cookie::parse(cookie).unwrap_or_else(|_| Cookie::from("")))
.collect() .collect()
}) })
} }
@ -167,7 +167,7 @@ impl ResponseExt for Response<Body> {
} }
fn remove_cookie(&mut self, name: String) { fn remove_cookie(&mut self, name: String) {
let mut cookie = Cookie::named(name); let mut cookie = Cookie::from(name);
cookie.set_path("/"); cookie.set_path("/");
cookie.set_max_age(Duration::seconds(1)); cookie.set_max_age(Duration::seconds(1));
if let Ok(val) = header::HeaderValue::from_str(&cookie.to_string()) { if let Ok(val) = header::HeaderValue::from_str(&cookie.to_string()) {

View File

@ -78,11 +78,11 @@ pub async fn set(req: Request<Body>) -> Result<Response<Body>, String> {
for &name in &PREFS { for &name in &PREFS {
match form.get(name) { match form.get(name) {
Some(value) => response.insert_cookie( Some(value) => response.insert_cookie(
Cookie::build(name.to_owned(), value.clone()) Cookie::build((name.to_owned(), value.clone()))
.path("/") .path("/")
.http_only(true) .http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52)) .expires(OffsetDateTime::now_utc() + Duration::weeks(52))
.finish(), .into(),
), ),
None => response.remove_cookie(name.to_string()), None => response.remove_cookie(name.to_string()),
}; };
@ -117,11 +117,11 @@ fn set_cookies_method(req: Request<Body>, remove_cookies: bool) -> Response<Body
for name in [PREFS.to_vec(), vec!["subscriptions", "filters"]].concat() { for name in [PREFS.to_vec(), vec!["subscriptions", "filters"]].concat() {
match form.get(name) { match form.get(name) {
Some(value) => response.insert_cookie( Some(value) => response.insert_cookie(
Cookie::build(name.to_owned(), value.clone()) Cookie::build((name.to_owned(), value.clone()))
.path("/") .path("/")
.http_only(true) .http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52)) .expires(OffsetDateTime::now_utc() + Duration::weeks(52))
.finish(), .into(),
), ),
None => { None => {
if remove_cookies { if remove_cookies {

View File

@ -177,11 +177,11 @@ pub async fn add_quarantine_exception(req: Request<Body>) -> Result<Response<Bod
let redir = param(&format!("?{}", req.uri().query().unwrap_or_default()), "redir").ok_or("Invalid URL")?; let redir = param(&format!("?{}", req.uri().query().unwrap_or_default()), "redir").ok_or("Invalid URL")?;
let mut response = redirect(redir); let mut response = redirect(redir);
response.insert_cookie( response.insert_cookie(
Cookie::build(&format!("allow_quaran_{}", subreddit.to_lowercase()), "true") Cookie::build((&format!("allow_quaran_{}", subreddit.to_lowercase()), "true"))
.path("/") .path("/")
.http_only(true) .http_only(true)
.expires(cookie::Expiration::Session) .expires(cookie::Expiration::Session)
.finish(), .into(),
); );
Ok(response) Ok(response)
} }
@ -289,22 +289,22 @@ pub async fn subscriptions_filters(req: Request<Body>) -> Result<Response<Body>,
response.remove_cookie("subscriptions".to_string()); response.remove_cookie("subscriptions".to_string());
} else { } else {
response.insert_cookie( response.insert_cookie(
Cookie::build("subscriptions", sub_list.join("+")) Cookie::build(("subscriptions", sub_list.join("+")))
.path("/") .path("/")
.http_only(true) .http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52)) .expires(OffsetDateTime::now_utc() + Duration::weeks(52))
.finish(), .into(),
); );
} }
if filters.is_empty() { if filters.is_empty() {
response.remove_cookie("filters".to_string()); response.remove_cookie("filters".to_string());
} else { } else {
response.insert_cookie( response.insert_cookie(
Cookie::build("filters", filters.join("+")) Cookie::build(("filters", filters.join("+")))
.path("/") .path("/")
.http_only(true) .http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52)) .expires(OffsetDateTime::now_utc() + Duration::weeks(52))
.finish(), .into(),
); );
} }

View File

@ -769,7 +769,7 @@ pub fn setting(req: &Request<Body>, name: &str) -> String {
if let Some(default) = crate::config::get_setting(&format!("LIBREDDIT_DEFAULT_{}", name.to_uppercase())) { if let Some(default) = crate::config::get_setting(&format!("LIBREDDIT_DEFAULT_{}", name.to_uppercase())) {
Cookie::new(name, default) Cookie::new(name, default)
} else { } else {
Cookie::named(name) Cookie::from(name)
} }
}) })
.value() .value()