-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crates/examples/sel4cp/http-server: Move mime logic into own module
- Loading branch information
Showing
3 changed files
with
32 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
crates/examples/sel4cp/http-server/pds/server/core/src/mime.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use core::str::pattern::Pattern; | ||
|
||
pub(crate) fn content_type_from_name(name: &str) -> &'static str { | ||
for (ext, ty) in MIME_ASSOCS { | ||
if ext.is_suffix_of(name) { | ||
return ty; | ||
} | ||
} | ||
DEFAULT_MIME_TYPE | ||
} | ||
|
||
const DEFAULT_MIME_TYPE: &str = "application/octet-stream"; | ||
|
||
const MIME_ASSOCS: &[(&str, &str)] = &[ | ||
(".css", "text/css"), | ||
(".html", "text/html; charset=utf-8"), | ||
(".ico", "image/vnd.microsoft.icon"), | ||
(".jpg", "image/jpeg"), | ||
(".js", "text/javascript; charset=utf-8"), | ||
(".mp4", "video/mp4"), | ||
(".pdf", "application/pdf"), | ||
(".png", "image/png"), | ||
(".svg", "image/svg+xml"), | ||
(".ttf", "font/ttf"), | ||
(".txt", "text/plain; charset=utf-8"), | ||
(".woff", "font/woff"), | ||
(".woff2", "font/woff2"), | ||
(".zip", "application/zip"), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters