/
media_types.py
137 lines (129 loc) · 5.07 KB
/
media_types.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from __future__ import annotations
import os
class MediaTypes:
__slots__ = ("types_map",)
def __init__(self, *, extra_types: dict[str, str] | None = None) -> None:
self.types_map = default_types()
if extra_types is not None:
self.types_map.update(extra_types)
def get_type(self, path: str) -> str:
name = os.path.basename(path).lower()
media_type = self.types_map.get(name)
if media_type is not None:
return media_type
extension = os.path.splitext(name)[1]
return self.types_map.get(extension, "application/octet-stream")
def default_types() -> dict[str, str]:
"""
We use our own set of default media types rather than the system-supplied
ones. This ensures consistent media type behaviour across varied
environments. The defaults are based on those shipped with nginx, with
some custom additions.
(Auto-generated by scripts/generate_default_media_types.py)
"""
return {
".3gp": "video/3gpp",
".3gpp": "video/3gpp",
".7z": "application/x-7z-compressed",
".ai": "application/postscript",
".asf": "video/x-ms-asf",
".asx": "video/x-ms-asf",
".atom": "application/atom+xml",
".avi": "video/x-msvideo",
".avif": "image/avif",
".bmp": "image/x-ms-bmp",
".cco": "application/x-cocoa",
".crt": "application/x-x509-ca-cert",
".css": "text/css",
".der": "application/x-x509-ca-cert",
".doc": "application/msword",
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
".ear": "application/java-archive",
".eot": "application/vnd.ms-fontobject",
".eps": "application/postscript",
".flv": "video/x-flv",
".gif": "image/gif",
".hqx": "application/mac-binhex40",
".htc": "text/x-component",
".htm": "text/html",
".html": "text/html",
".ico": "image/x-icon",
".jad": "text/vnd.sun.j2me.app-descriptor",
".jar": "application/java-archive",
".jardiff": "application/x-java-archive-diff",
".jng": "image/x-jng",
".jnlp": "application/x-java-jnlp-file",
".jpeg": "image/jpeg",
".jpg": "image/jpeg",
".js": "text/javascript",
".json": "application/json",
".kar": "audio/midi",
".kml": "application/vnd.google-earth.kml+xml",
".kmz": "application/vnd.google-earth.kmz",
".m3u8": "application/vnd.apple.mpegurl",
".m4a": "audio/x-m4a",
".m4v": "video/x-m4v",
".md": "text/markdown",
".mid": "audio/midi",
".midi": "audio/midi",
".mjs": "text/javascript",
".mml": "text/mathml",
".mng": "video/x-mng",
".mov": "video/quicktime",
".mp3": "audio/mpeg",
".mp4": "video/mp4",
".mpeg": "video/mpeg",
".mpg": "video/mpeg",
".odg": "application/vnd.oasis.opendocument.graphics",
".odp": "application/vnd.oasis.opendocument.presentation",
".ods": "application/vnd.oasis.opendocument.spreadsheet",
".odt": "application/vnd.oasis.opendocument.text",
".ogg": "audio/ogg",
".pdb": "application/x-pilot",
".pdf": "application/pdf",
".pem": "application/x-x509-ca-cert",
".pl": "application/x-perl",
".pm": "application/x-perl",
".png": "image/png",
".ppt": "application/vnd.ms-powerpoint",
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
".prc": "application/x-pilot",
".ps": "application/postscript",
".ra": "audio/x-realaudio",
".rar": "application/x-rar-compressed",
".rpm": "application/x-redhat-package-manager",
".rss": "application/rss+xml",
".rtf": "application/rtf",
".run": "application/x-makeself",
".sea": "application/x-sea",
".shtml": "text/html",
".sit": "application/x-stuffit",
".svg": "image/svg+xml",
".svgz": "image/svg+xml",
".swf": "application/x-shockwave-flash",
".tcl": "application/x-tcl",
".tif": "image/tiff",
".tiff": "image/tiff",
".tk": "application/x-tcl",
".ts": "video/mp2t",
".txt": "text/plain",
".war": "application/java-archive",
".wasm": "application/wasm",
".wbmp": "image/vnd.wap.wbmp",
".webm": "video/webm",
".webp": "image/webp",
".wml": "text/vnd.wap.wml",
".wmlc": "application/vnd.wap.wmlc",
".wmv": "video/x-ms-wmv",
".woff": "application/font-woff",
".woff2": "font/woff2",
".xhtml": "application/xhtml+xml",
".xls": "application/vnd.ms-excel",
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
".xml": "text/xml",
".xpi": "application/x-xpinstall",
".xspf": "application/xspf+xml",
".zip": "application/zip",
"apple-app-site-association": "application/pkc7-mime",
"crossdomain.xml": "text/x-cross-domain-policy",
}