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_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)?
|
||||||
disposition: if query.inline.is_some() {
|
.set_content_disposition(ContentDisposition {
|
||||||
DispositionType::Inline
|
disposition: if query.inline.is_some() {
|
||||||
} else {
|
DispositionType::Inline
|
||||||
DispositionType::Attachment
|
} else {
|
||||||
},
|
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")]
|
||||||
|
|
Loading…
Reference in a new issue