relay/src/routes/statics.rs

25 lines
834 B
Rust
Raw Normal View History

2020-03-23 17:38:39 +00:00
use crate::templates::statics::StaticFile;
use actix_web::{
http::header::{CacheControl, CacheDirective, ContentType},
2020-03-23 17:38:39 +00:00
web, HttpResponse,
};
2021-11-23 22:19:59 +00:00
#[allow(clippy::async_yields_async)]
#[tracing::instrument(name = "Statics")]
2021-02-10 04:17:20 +00:00
pub(crate) async fn route(filename: web::Path<String>) -> HttpResponse {
2020-03-23 17:38:39 +00:00
if let Some(data) = StaticFile::get(&filename.into_inner()) {
HttpResponse::Ok()
2021-02-11 00:00:11 +00:00
.insert_header(CacheControl(vec![
CacheDirective::Public,
CacheDirective::MaxAge(60 * 60 * 24),
CacheDirective::Extension("immutable".to_owned(), None),
]))
2021-02-11 00:00:11 +00:00
.insert_header(ContentType(data.mime.clone()))
2020-03-23 17:38:39 +00:00
.body(data.content)
} else {
HttpResponse::NotFound()
.reason("No such static file.")
.finish()
}
}