blob: cabc6f8d0a748fc5785ba5d669d3e62a10ade40c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
use std::time::{Duration, SystemTime};
use actix_web::{http::header, web, HttpResponse};
use crate::templates::statics::StaticFile;
static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60);
pub async fn file(path: web::Path<String>) -> HttpResponse {
let name = &path.into_inner();
if let Some(data) = StaticFile::get(name) {
let far_expires = SystemTime::now() + FAR;
HttpResponse::Ok()
.insert_header(header::Expires(far_expires.into()))
.insert_header(header::ContentType(data.mime.clone()))
.body(data.content)
} else {
HttpResponse::NotFound()
.reason("No such static file.")
.finish()
}
}
|