|
3 | 3 | use crate::utils::{ |
4 | 4 | Post, Preferences, Subreddit, catch_random, error, filter_posts, format_num, format_url, info, nsfw_landing, param, redirect, rewrite_urls, setting, setting_or_default, template, to_absolute_url, val |
5 | 5 | }; |
6 | | -use crate::{client::json, server::RequestExt, server::ResponseExt}; |
| 6 | +use crate::{client::json, server::{build_cookie, build_session_cookie, RequestExt, ResponseExt}}; |
7 | 7 | use crate::{config, utils}; |
8 | 8 | use askama::Template; |
9 | | -use cookie::Cookie; |
10 | 9 | use htmlescape::decode_html; |
11 | 10 | use hyper::{Request, Response}; |
12 | 11 | use crate::server::{full, Body}; |
@@ -216,14 +215,7 @@ pub async fn add_quarantine_exception(req: Request<Body>) -> Result<Response<Bod |
216 | 215 | let subreddit = req.param("sub").ok_or("Invalid URL")?; |
217 | 216 | let redir = param(&format!("?{}", req.uri().query().unwrap_or_default()), "redir").ok_or("Invalid URL")?; |
218 | 217 | let mut response = redirect(&redir); |
219 | | - response.insert_cookie( |
220 | | - Cookie::build((&format!("allow_quaran_{}", subreddit.to_lowercase()), "true")) |
221 | | - .path("/") |
222 | | - .http_only(true) |
223 | | - .secure(true) |
224 | | - .expires(cookie::Expiration::Session) |
225 | | - .into(), |
226 | | - ); |
| 218 | + response.insert_cookie(build_session_cookie(format!("allow_quaran_{}", subreddit.to_lowercase()), "true")); |
227 | 219 | Ok(response) |
228 | 220 | } |
229 | 221 |
|
@@ -387,14 +379,7 @@ pub async fn subscriptions_filters(req: Request<Body>) -> Result<Response<Body>, |
387 | 379 | format!("subscriptions{subscriptions_number}") |
388 | 380 | }; |
389 | 381 |
|
390 | | - response.insert_cookie( |
391 | | - Cookie::build((subscriptions_cookie, list)) |
392 | | - .path("/") |
393 | | - .http_only(true) |
394 | | - .secure(true) |
395 | | - .expires(OffsetDateTime::now_utc() + Duration::weeks(52)) |
396 | | - .into(), |
397 | | - ); |
| 382 | + response.insert_cookie(build_cookie(subscriptions_cookie, list, OffsetDateTime::now_utc() + Duration::weeks(52))); |
398 | 383 |
|
399 | 384 | subscriptions_number_to_delete_from += 1; |
400 | 385 | } |
@@ -436,14 +421,7 @@ pub async fn subscriptions_filters(req: Request<Body>) -> Result<Response<Body>, |
436 | 421 | format!("filters{filters_number}") |
437 | 422 | }; |
438 | 423 |
|
439 | | - response.insert_cookie( |
440 | | - Cookie::build((filters_cookie, list)) |
441 | | - .path("/") |
442 | | - .http_only(true) |
443 | | - .secure(true) |
444 | | - .expires(OffsetDateTime::now_utc() + Duration::weeks(52)) |
445 | | - .into(), |
446 | | - ); |
| 424 | + response.insert_cookie(build_cookie(filters_cookie, list, OffsetDateTime::now_utc() + Duration::weeks(52))); |
447 | 425 |
|
448 | 426 | filters_number_to_delete_from += 1; |
449 | 427 | } |
|
0 commit comments