mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
static assets caching
This commit is contained in:
@@ -14,13 +14,14 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
use std::borrow::Cow;
|
||||
|
||||
use actix_web::body::Body;
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use actix_web::{http::header, web, HttpResponse, Responder};
|
||||
use mime_guess::from_path;
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use crate::CACHE_AGE;
|
||||
|
||||
pub const DOCS: routes::Docs = routes::Docs::new();
|
||||
|
||||
@@ -62,6 +63,9 @@ pub fn handle_embedded_file(path: &str) -> HttpResponse {
|
||||
Cow::Owned(bytes) => bytes.into(),
|
||||
};
|
||||
HttpResponse::Ok()
|
||||
.set(header::CacheControl(vec![header::CacheDirective::MaxAge(
|
||||
CACHE_AGE,
|
||||
)]))
|
||||
.content_type(from_path(path).first_or_octet_stream().as_ref())
|
||||
.body(body)
|
||||
}
|
||||
|
||||
@@ -61,9 +61,10 @@ pub static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub static PKG_NAME: &str = env!("CARGO_PKG_NAME");
|
||||
pub static PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
|
||||
pub static PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
|
||||
|
||||
pub static VERIFICATION_PATH: &str = "mcaptchaVerificationChallenge.json";
|
||||
|
||||
pub const CACHE_AGE: u32 = 365 * 24 * 3600;
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
|
||||
@@ -14,14 +14,15 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
use std::borrow::Cow;
|
||||
|
||||
use actix_web::body::Body;
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use actix_web::{get, http::header, web, HttpResponse, Responder};
|
||||
use cache_buster::Files;
|
||||
use mime_guess::from_path;
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use crate::CACHE_AGE;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "static/"]
|
||||
@@ -34,7 +35,11 @@ pub fn handle_embedded_file(path: &str) -> HttpResponse {
|
||||
Cow::Borrowed(bytes) => bytes.into(),
|
||||
Cow::Owned(bytes) => bytes.into(),
|
||||
};
|
||||
|
||||
HttpResponse::Ok()
|
||||
.set(header::CacheControl(vec![header::CacheDirective::MaxAge(
|
||||
CACHE_AGE,
|
||||
)]))
|
||||
.content_type(from_path(path).first_or_octet_stream().as_ref())
|
||||
.body(body)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user