diff --git a/src/main.rs b/src/main.rs index 799d046..5f4adc9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,8 @@ use actix::Arbiter; -use actix_web::{middleware::Logger, web, App, HttpServer}; +use actix_web::{ + middleware::{Compress, Logger}, + web, App, HttpServer, +}; mod apub; mod args; @@ -112,6 +115,7 @@ async fn main() -> Result<(), anyhow::Error> { App::new() .wrap(Logger::default()) + .wrap(Compress::default()) .data(db.clone()) .data(state.clone()) .data(state.requests()) diff --git a/src/requests.rs b/src/requests.rs index c78b252..2c84e14 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -3,7 +3,7 @@ use activitystreams::primitives::XsdAnyUri; use actix_web::client::Client; use bytes::Bytes; use http_signature_normalization_actix::prelude::*; -use log::error; +use log::{error, info}; use rsa::{hash::Hashes, padding::PaddingScheme, RSAPrivateKey}; use sha2::{Digest, Sha256}; @@ -65,6 +65,7 @@ impl Requests { } pub async fn fetch_bytes(&self, url: &str) -> Result<(String, Bytes), MyError> { + info!("Fetching bytes for {}", url); let mut res = self .client .get(url) diff --git a/src/routes/media.rs b/src/routes/media.rs index 64b4b43..30cfc53 100644 --- a/src/routes/media.rs +++ b/src/routes/media.rs @@ -20,7 +20,10 @@ pub async fn route( .store_bytes(uuid, content_type.clone(), bytes.clone()) .await; - return Ok(HttpResponse::Ok().content_type(content_type).body(bytes)); + return Ok(HttpResponse::Ok() + .content_type(content_type) + .header("Cache-Control", "public, max-age=1200, immutable") + .body(bytes)); } Ok(HttpResponse::NotFound().finish())