23 lines
614 B
Rust
23 lines
614 B
Rust
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
|
|
|
/// Build an inline `Content-Disposition` header value for a given filename.
|
|
pub fn inline_content_disposition(filename: &str) -> Option<String> {
|
|
if filename.is_empty() {
|
|
return None;
|
|
}
|
|
|
|
let sanitized: String = filename
|
|
.chars()
|
|
.map(|ch| match ch {
|
|
'"' | '\\' => '_',
|
|
_ => ch,
|
|
})
|
|
.collect();
|
|
let encoded = utf8_percent_encode(&sanitized, NON_ALPHANUMERIC);
|
|
|
|
Some(format!(
|
|
"inline; filename=\"{}\"; filename*=UTF-8''{}",
|
|
sanitized, encoded
|
|
))
|
|
}
|