send cache-control (immutable, 31) for /raw/{hash}
This commit is contained in:
parent
de5ce5b7e1
commit
add8371776
1 changed files with 19 additions and 11 deletions
|
@ -11,9 +11,9 @@ use crate::util::jobs::JobContainer;
|
|||
use actix_files::NamedFile;
|
||||
use actix_multipart::Multipart;
|
||||
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound};
|
||||
use actix_web::http;
|
||||
use actix_web::http::header::{ContentDisposition, DispositionType};
|
||||
use actix_web::http::header::{CacheControl, CacheDirective, ContentDisposition, DispositionType};
|
||||
use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse};
|
||||
use actix_web::{http, Responder};
|
||||
use anyhow::{anyhow, Result};
|
||||
use futures_util::TryStreamExt;
|
||||
use log::{debug, info, trace};
|
||||
|
@ -52,7 +52,7 @@ pub async fn get_raw(
|
|||
state: web::Data<State>,
|
||||
web::Query(query): web::Query<RawRequest>,
|
||||
hash: web::Path<String>,
|
||||
) -> Result<Either<NamedFile, HttpResponse>, Error> {
|
||||
) -> Result<impl Responder, Error> {
|
||||
let address =
|
||||
Address::decode(&b58_decode(hash.into_inner()).map_err(ErrorInternalServerError)?)
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
@ -76,14 +76,22 @@ pub async fn get_raw(
|
|||
|
||||
if query.native.is_none() {
|
||||
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() {
|
||||
DispositionType::Inline
|
||||
} else {
|
||||
DispositionType::Attachment
|
||||
},
|
||||
parameters: vec![],
|
||||
}),
|
||||
})
|
||||
.with_header(
|
||||
http::header::CACHE_CONTROL,
|
||||
CacheControl(vec![
|
||||
CacheDirective::MaxAge(2678400),
|
||||
CacheDirective::Extension("immutable".into(), None),
|
||||
]),
|
||||
),
|
||||
))
|
||||
} else if state.desktop_enabled {
|
||||
#[cfg(feature = "desktop")]
|
||||
|
|
Loading…
Reference in a new issue