`Cache-Control` overwrites `Expires`
This commit is contained in:
parent
5ef0a218c2
commit
0fde5aaa2d
@ -17,12 +17,11 @@ use crate::{
|
|||||||
statics::FAVICON,
|
statics::FAVICON,
|
||||||
};
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
http::header::{self, CacheControl, CacheDirective, Expires},
|
http::header::{self, CacheControl, CacheDirective},
|
||||||
middleware, web, App, Error, HttpResponse, HttpServer,
|
middleware, web, App, Error, HttpResponse, HttpServer,
|
||||||
};
|
};
|
||||||
use awc::{http::StatusCode, Client};
|
use awc::{http::StatusCode, Client};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use std::time::{Duration, SystemTime};
|
|
||||||
|
|
||||||
fn proxy_file<T: Service>(
|
fn proxy_file<T: Service>(
|
||||||
client: web::Data<Client>,
|
client: web::Data<Client>,
|
||||||
@ -42,13 +41,11 @@ fn proxy_file<T: Service>(
|
|||||||
.and_then(move |response| match response.status() {
|
.and_then(move |response| match response.status() {
|
||||||
StatusCode::OK => {
|
StatusCode::OK => {
|
||||||
let mime = mime_guess::guess_mime_type(&data.file);
|
let mime = mime_guess::guess_mime_type(&data.file);
|
||||||
let expiration = SystemTime::now() + Duration::from_secs(2_592_000_000);
|
|
||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_type(mime.to_string().as_str())
|
.content_type(mime.to_string().as_str())
|
||||||
.set(Expires(expiration.into()))
|
|
||||||
.set(CacheControl(vec![
|
.set(CacheControl(vec![
|
||||||
CacheDirective::MaxAge(2_592_000_000),
|
|
||||||
CacheDirective::Public,
|
CacheDirective::Public,
|
||||||
|
CacheDirective::MaxAge(2_592_000_000),
|
||||||
]))
|
]))
|
||||||
.streaming(response))
|
.streaming(response))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user