(path: &str)
| 94 | } |
| 95 | |
| 96 | fn safe_relative_path(path: &str) -> Option<PathBuf> { |
| 97 | let trimmed = path.trim_start_matches('/'); |
| 98 | if trimmed.is_empty() { |
| 99 | return Some(PathBuf::from("index.html")); |
| 100 | } |
| 101 | |
| 102 | let mut relative = PathBuf::new(); |
| 103 | for component in Path::new(trimmed).components() { |
| 104 | match component { |
| 105 | Component::Normal(part) => relative.push(part), |
| 106 | Component::CurDir => {} |
| 107 | Component::ParentDir | Component::RootDir | Component::Prefix(_) => return None, |
| 108 | } |
| 109 | } |
| 110 | Some(relative) |
| 111 | } |
| 112 | |
| 113 | fn content_type_for_path(path: &Path) -> &'static str { |
| 114 | match path.extension().and_then(|extension| extension.to_str()) { |
no test coverage detected