-
Notifications
You must be signed in to change notification settings - Fork 15
/
mimes.odin
67 lines (60 loc) · 1.32 KB
/
mimes.odin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package http
import "core:path/filepath"
Mime_Type :: enum {
Plain,
Css,
Csv,
Gif,
Html,
Ico,
Jpeg,
Js,
Json,
Png,
Svg,
Url_Encoded,
Xml,
Zip,
Wasm,
}
mime_from_extension :: proc(s: string) -> Mime_Type {
//odinfmt:disable
switch filepath.ext(s) {
case ".html": return .Html
case ".js": return .Js
case ".css": return .Css
case ".csv": return .Csv
case ".xml": return .Xml
case ".zip": return .Zip
case ".json": return .Json
case ".ico": return .Ico
case ".gif": return .Gif
case ".jpeg": return .Jpeg
case ".png": return .Png
case ".svg": return .Svg
case ".wasm": return .Wasm
case: return .Plain
}
//odinfmt:enable
}
@(private="file")
_mime_to_content_type := [Mime_Type]string{
.Plain = "text/plain",
.Css = "text/css",
.Csv = "text/csv",
.Gif = "image/gif",
.Html = "text/html",
.Ico = "application/vnd.microsoft.ico",
.Jpeg = "image/jpeg",
.Js = "application/javascript",
.Json = "application/json",
.Png = "image/png",
.Svg = "image/svg+xml",
.Url_Encoded = "application/x-www-form-urlencoded",
.Xml = "text/xml",
.Zip = "application/zip",
.Wasm = "application/wasm",
}
mime_to_content_type :: proc(m: Mime_Type) -> string {
return _mime_to_content_type[m]
}