mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-30 01:20:00 -07:00
global: snapshot
This commit is contained in:
@@ -41,6 +41,7 @@ pub trait HeaderMapUtils {
|
||||
fn insert_content_type_application_javascript(&mut self);
|
||||
fn insert_content_type_application_json(&mut self);
|
||||
fn insert_content_type_application_manifest_json(&mut self);
|
||||
fn insert_content_type_application_pdf(&mut self);
|
||||
fn insert_content_type_text_css(&mut self);
|
||||
fn insert_content_type_text_html(&mut self);
|
||||
fn insert_content_type_text_plain(&mut self);
|
||||
@@ -148,6 +149,7 @@ impl HeaderMapUtils for HeaderMap {
|
||||
"html" => self.insert_content_type_text_html(),
|
||||
"css" => self.insert_content_type_text_css(),
|
||||
"txt" => self.insert_content_type_text_plain(),
|
||||
"pdf" => self.insert_content_type_application_pdf(),
|
||||
"woff2" => self.insert_content_type_font_woff2(),
|
||||
"ico" => self.insert_content_type_image_icon(),
|
||||
"jpg" | "jpeg" => self.insert_content_type_image_jpeg(),
|
||||
@@ -190,6 +192,10 @@ impl HeaderMapUtils for HeaderMap {
|
||||
);
|
||||
}
|
||||
|
||||
fn insert_content_type_application_pdf(&mut self) {
|
||||
self.insert(header::CONTENT_TYPE, "application/pdf".parse().unwrap());
|
||||
}
|
||||
|
||||
fn insert_content_type_text_css(&mut self) {
|
||||
self.insert(header::CONTENT_TYPE, "text/css".parse().unwrap());
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::header_map::HeaderMapUtils;
|
||||
|
||||
use super::minify_js;
|
||||
|
||||
const WEBSITE_PATH: &str = "../website";
|
||||
const WEBSITE_PATH: &str = "../website/";
|
||||
|
||||
pub async fn file_handler(headers: HeaderMap, path: extract::Path<String>) -> Response {
|
||||
let path = path.0.replace("..", "").replace("\\", "");
|
||||
@@ -46,6 +46,8 @@ pub async fn index_handler(headers: HeaderMap) -> Response {
|
||||
}
|
||||
|
||||
fn path_to_response(headers: HeaderMap, path: &Path) -> Response {
|
||||
log(&path.to_str().unwrap().replace(WEBSITE_PATH, ""));
|
||||
|
||||
let (date, response) = headers.check_if_modified_since(path).unwrap();
|
||||
|
||||
if let Some(response) = response {
|
||||
@@ -79,8 +81,14 @@ fn path_to_response(headers: HeaderMap, path: &Path) -> Response {
|
||||
let serialized_path = path.to_str().unwrap();
|
||||
|
||||
if serialized_path.contains("fonts/")
|
||||
|| serialized_path.contains("assets/pwa/")
|
||||
|| serialized_path.contains("assets/")
|
||||
|| serialized_path.contains("packages/")
|
||||
|| path.extension().is_some_and(|extension| {
|
||||
extension == "pdf"
|
||||
|| extension == "jpg"
|
||||
|| extension == "png"
|
||||
|| extension == "woff2"
|
||||
})
|
||||
{
|
||||
headers.insert_cache_control_immutable();
|
||||
} else {
|
||||
@@ -94,5 +102,5 @@ fn path_to_response(headers: HeaderMap, path: &Path) -> Response {
|
||||
}
|
||||
|
||||
fn str_to_path(path: &str) -> PathBuf {
|
||||
PathBuf::from(&format!("{WEBSITE_PATH}/{path}"))
|
||||
PathBuf::from(&format!("{WEBSITE_PATH}{path}"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user