diff --git a/Cargo.toml b/Cargo.toml index 840972c..bbe29fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,3 +37,12 @@ path-dedot = "1" default = ["native-tls"] only-openssl = ["native-tls", "openssl"] native-tls = ["hyper-native-tls"] + + +[profile.release] +opt-level = 3 # 最高优化级别 +lto = true # 链接时优化 +codegen-units = 1 # 尽可能合并代码生成单元 +panic = 'abort' # 恐慌时立即终止,而不是展开(减小二进制大小) +strip = true # 从二进制文件中删除调试信息 + diff --git a/src/main.rs b/src/main.rs index 038be55..42efd25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -919,8 +919,17 @@ impl MainHandler { } // Set mime type let mime = mime_types::from_path(path).first_or_octet_stream(); - resp.headers - .set_raw("content-type", vec![mime.to_string().into_bytes()]); + + // Fix messy code for non english issue: explicitly specify UTF-8 encoding for text files + let content_type = if mime.type_() == "text" { + format!("{}; charset=utf-8", mime) + } else if mime.type_() == "application" && mime.subtype() == "x-yaml" { + format!("text/yaml; charset=utf-8") + } else { + mime.to_string() + }; + resp.headers.set_raw("content-type", vec![content_type.into_bytes()]); + if self.coop { resp.headers.set_raw( "Cross-Origin-Opener-Policy", diff --git a/tests/hello.txt b/tests/hello.txt new file mode 100644 index 0000000..84bd9f0 --- /dev/null +++ b/tests/hello.txt @@ -0,0 +1,7 @@ +Language (English) "Hello, World!" Translation +English Hello, World! +Chinese (Simplified) 你好,世界! (Nǐ hǎo, shìjiè!) +Russian Здравствуй, мир! (Zdravstvuy, mir!) +Japanese こんにちは、世界! (Konnichiwa, sekai!) + +