send cache-control (immutable, 31) for /raw/{hash}

This commit is contained in:
Tomáš Mládek 2022-02-15 01:21:04 +01:00
parent de5ce5b7e1
commit add8371776
No known key found for this signature in database
GPG key ID: 65E225C8B3E2ED8A

View file

@ -11,9 +11,9 @@ use crate::util::jobs::JobContainer;
use actix_files::NamedFile; use actix_files::NamedFile;
use actix_multipart::Multipart; use actix_multipart::Multipart;
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound}; use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound};
use actix_web::http; use actix_web::http::header::{CacheControl, CacheDirective, ContentDisposition, DispositionType};
use actix_web::http::header::{ContentDisposition, DispositionType};
use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse}; use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse};
use actix_web::{http, Responder};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use futures_util::TryStreamExt; use futures_util::TryStreamExt;
use log::{debug, info, trace}; use log::{debug, info, trace};
@ -52,7 +52,7 @@ pub async fn get_raw(
state: web::Data<State>, state: web::Data<State>,
web::Query(query): web::Query<RawRequest>, web::Query(query): web::Query<RawRequest>,
hash: web::Path<String>, hash: web::Path<String>,
) -> Result<Either<NamedFile, HttpResponse>, Error> { ) -> Result<impl Responder, Error> {
let address = let address =
Address::decode(&b58_decode(hash.into_inner()).map_err(ErrorInternalServerError)?) Address::decode(&b58_decode(hash.into_inner()).map_err(ErrorInternalServerError)?)
.map_err(ErrorInternalServerError)?; .map_err(ErrorInternalServerError)?;
@ -76,14 +76,22 @@ pub async fn get_raw(
if query.native.is_none() { if query.native.is_none() {
Ok(Either::A( Ok(Either::A(
NamedFile::open(file_path)?.set_content_disposition(ContentDisposition { NamedFile::open(file_path)?
.set_content_disposition(ContentDisposition {
disposition: if query.inline.is_some() { disposition: if query.inline.is_some() {
DispositionType::Inline DispositionType::Inline
} else { } else {
DispositionType::Attachment DispositionType::Attachment
}, },
parameters: vec![], parameters: vec![],
}), })
.with_header(
http::header::CACHE_CONTROL,
CacheControl(vec![
CacheDirective::MaxAge(2678400),
CacheDirective::Extension("immutable".into(), None),
]),
),
)) ))
} else if state.desktop_enabled { } else if state.desktop_enabled {
#[cfg(feature = "desktop")] #[cfg(feature = "desktop")]