diff --git a/src/models/response_wrapper.rs b/src/models/response_wrapper.rs index 27f8153..6fdb617 100644 --- a/src/models/response_wrapper.rs +++ b/src/models/response_wrapper.rs @@ -8,7 +8,8 @@ use std::time::SystemTime; pub enum ResponseWrapper { MetaInterfaceResponse(R), - PasteContentResponse(R, SystemTime), + PrettyPasteContentResponse(R, SystemTime), + RawPasteContentResponse(R, SystemTime), Redirect(Box), NotFound(String), ServerError(String), @@ -19,8 +20,12 @@ impl<'r, 'o: 'r, R: Responder<'r, 'o>> ResponseWrapper { Self::MetaInterfaceResponse(responder) } - pub fn paste_response(responder: R, modified: SystemTime) -> Self { - Self::PasteContentResponse(responder, modified) + pub fn pretty_paste_response(responder: R, modified: SystemTime) -> Self { + Self::PrettyPasteContentResponse(responder, modified) + } + + pub fn raw_paste_response(responder: R, modified: SystemTime) -> Self { + Self::RawPasteContentResponse(responder, modified) } pub fn redirect(redirect: Redirect) -> Self { @@ -51,15 +56,31 @@ impl<'r, 'o: 'r, R: Responder<'r, 'o>> Responder<'r, 'o> MetaInterfaceResponse(sup) => response .join(sup.respond_to(request)?) .raw_header("ETag", &*crate::BINARY_ETAG) + .raw_header( + "Cache-Control", + "max-age=604800, stale-while-revalidate=86400", + ) + .ok(), + + PrettyPasteContentResponse(sup, modified) => response + .join(sup.respond_to(request)?) + .raw_header("Last-Modified", http_strftime(modified)) + .raw_header( + "Cache-Control", + "max-age=604800, stale-while-revalidate=86400", + ) .ok(), - PasteContentResponse(sup, modified) => response + + RawPasteContentResponse(sup, modified) => response .join(sup.respond_to(request)?) .raw_header("Last-Modified", http_strftime(modified)) + .raw_header("Cache-Control", "max-age=604800, immutable") .ok(), + Redirect(sup) => response.join(sup.respond_to(request)?).ok(), + NotFound(s) => { let body = format!("Unable to find entity '{}'", s); - response .sized_body(body.len(), Cursor::new(body)) .status(Status::NotFound) diff --git a/src/routes/index.rs b/src/routes/index.rs index 93b123a..2fa7a6e 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -2,9 +2,11 @@ use rocket_dyn_templates::Template; use std::collections::HashMap; +use crate::models::response_wrapper::ResponseWrapper; + #[get("/")] -pub async fn index() -> Option