-
Notifications
You must be signed in to change notification settings - Fork 205
fix messy code when send_file text #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
cba327f
a7eade3
c04d6ea
e71e845
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -921,6 +921,15 @@ impl MainHandler { | |
let mime = mime_types::from_path(path).first_or_octet_stream(); | ||
resp.headers | ||
.set_raw("content-type", vec![mime.to_string().into_bytes()]); | ||
|
||
// 修复中文乱码问题:对于文本类型的文件,明确指定 UTF-8 编码 | ||
let content_type = if mime.type_() == "text" { | ||
format!("{}; charset=utf-8", mime) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the type is text, first read the content (at most 512 bytes), and use |
||
} else { | ||
mime.to_string() | ||
}; | ||
resp.headers.set_raw("content-type", vec![content_type.into_bytes()]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
if self.coop { | ||
resp.headers.set_raw( | ||
"Cross-Origin-Opener-Policy", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is unnecessary. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English comment please.