From: Dessalines Date: Thu, 22 Oct 2020 16:53:53 +0000 (-0500) Subject: Remove cache headers. Fixes #1222 X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/%7BdocsUrl%7D?a=commitdiff_plain;h=e7d390509384f843b40c6ed0dccd81dbf07d3043;p=lemmy.git Remove cache headers. Fixes #1222 --- diff --git a/lemmy_utils/src/lib.rs b/lemmy_utils/src/lib.rs index 19e7bb83..eecb7b2d 100644 --- a/lemmy_utils/src/lib.rs +++ b/lemmy_utils/src/lib.rs @@ -78,6 +78,4 @@ lazy_static! { Settings::get().hostname )) .unwrap(); - pub static ref CACHE_CONTROL_REGEX: Regex = - Regex::new("^((text|image)/.+|application/javascript)$").unwrap(); } diff --git a/src/main.rs b/src/main.rs index dea60c0a..811c920a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,38 +2,23 @@ extern crate diesel_migrations; use actix::prelude::*; -use actix_web::{ - body::Body, - dev::{Service, ServiceRequest, ServiceResponse}, - http::{ - header::{CACHE_CONTROL, CONTENT_TYPE}, - HeaderValue, - }, - *, -}; +use actix_web::*; use diesel::{ r2d2::{ConnectionManager, Pool}, PgConnection, }; -use lazy_static::lazy_static; use lemmy_api::match_websocket_operation; use lemmy_apub::activity_queue::create_activity_queue; use lemmy_db::get_database_url_from_env; use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit}; use lemmy_server::{code_migrations::run_advanced_migrations, routes::*}; use lemmy_structs::blocking; -use lemmy_utils::{settings::Settings, LemmyError, CACHE_CONTROL_REGEX}; +use lemmy_utils::{settings::Settings, LemmyError}; use lemmy_websocket::{chat_server::ChatServer, LemmyContext}; use reqwest::Client; use std::sync::Arc; use tokio::sync::Mutex; -lazy_static! { - // static ref CACHE_CONTROL_VALUE: String = format!("public, max-age={}", 365 * 24 * 60 * 60); - // Test out 1 hour here, this is breaking some things - static ref CACHE_CONTROL_VALUE: String = format!("public, max-age={}", 60 * 60); -} - embed_migrations!(); #[actix_web::main] @@ -90,7 +75,6 @@ async fn main() -> Result<(), LemmyError> { ); let rate_limiter = rate_limiter.clone(); App::new() - .wrap_fn(add_cache_headers) .wrap(middleware::Logger::default()) .data(context) // The routes @@ -108,23 +92,3 @@ async fn main() -> Result<(), LemmyError> { Ok(()) } - -fn add_cache_headers( - req: ServiceRequest, - srv: &mut S, -) -> impl Future> -where - S: Service, Error = Error>, -{ - let fut = srv.call(req); - async move { - let mut res = fut.await?; - if let Some(content_type) = res.headers().get(CONTENT_TYPE) { - if CACHE_CONTROL_REGEX.is_match(content_type.to_str().unwrap()) { - let header_val = HeaderValue::from_static(&CACHE_CONTROL_VALUE); - res.headers_mut().insert(CACHE_CONTROL, header_val); - } - } - Ok(res) - } -}