From 0f506fc41b473f91648788f6c4e4f1f147a4a672 Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Wed, 6 Jan 2021 11:11:04 -0800 Subject: [PATCH] Cache proxied media --- src/proxy.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/proxy.rs b/src/proxy.rs index 786617f..c9502b0 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -33,14 +33,20 @@ pub async fn handler(web::Path(b64): web::Path) -> Result .send() .await .map_err(Error::from) - .map(|res| HttpResponse::build(res.status()).streaming(res)) + .map(|res| + HttpResponse::build(res.status()) + .header("Cache-Control", "public, max-age=1209600, s-maxage=86400, must-revalidate") + .header("Content-Length", res.headers().get("Content-Length").unwrap().to_owned()) + .header("Content-Type", res.headers().get("Content-Type").unwrap().to_owned()) + .streaming(res) + ) } else { Err(error::ErrorForbidden("Resource must be from Reddit")) } } - Err(_) => Err(error::ErrorBadRequest("Can't parse encoded base64 URL")), + Err(_) => Err(error::ErrorBadRequest("Can't parse base64 into URL")), } } - Err(_) => Err(error::ErrorBadRequest("Can't decode base64 URL")), + Err(_) => Err(error::ErrorBadRequest("Can't decode base64")), } }