rouille/
assets.rs

1// Copyright (c) 2016 The Rouille developers
2// Licensed under the Apache License, Version 2.0
3// <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
6// at your option. All files in the project carrying such
7// notice may not be copied, modified, or distributed except
8// according to those terms.
9
10use std::fs;
11use std::path::Path;
12
13use filetime;
14use time;
15
16use Request;
17use Response;
18
19/// Searches inside `path` for a file that matches the given request. If a file is found,
20/// returns a `Response` that would serve this file if returned. If no file is found, a 404
21/// response is returned instead.
22///
23/// The value of the `Content-Type` header of the response is guessed based on the file's
24/// extension. If you wish so, you can modify that `Content-Type` by modifying the `Response`
25/// object returned by this function.
26///
27/// # Example
28///
29/// In this example, a request made for example to `/test.txt` will return the file
30/// `public/test.txt` (relative to the current working directory, which is usually the location
31/// of the `Cargo.toml`) if it exists.
32///
33/// ```no_run
34/// rouille::start_server("localhost:8000", move |request| {
35///     let response = rouille::match_assets(&request, "public");
36///     if response.is_success() {
37///         return response;
38///     }
39///
40///     // ...
41///     # panic!()
42/// });
43/// ```
44///
45/// # Security
46///
47/// Everything inside the directory that you pass as `path` is potentially accessible by any
48/// client. **Do not use assume that client won't be able to guess the URL of a sensitive file**.
49/// All sensitive files should require a login/password to be accessed.
50///
51/// If you want to serve sensitive files, you are encouraged to put them in a different directory
52/// than public files, and call `match_assets` once for public files and once for private files
53/// after you checked the user's credentials.
54/// Only call `match_assets` **after** you know that the user can have access to all the files
55/// that can be served.
56///
57/// If you manage the user's accesses per-file, use a white list of authorized files instead of a
58/// black list of forbidden files. Files can potentially be accessed from multiple different URLs
59/// and a black list may not cover everything.
60///
61/// # Example with prefix
62///
63/// Sometimes you want to add a prefix to the URL of your static files. To do that, you can use
64/// the `remove_prefix` method on `Request`.
65///
66/// ```no_run
67/// rouille::start_server("localhost:8000", move |request| {
68///     if let Some(request) = request.remove_prefix("/static") {
69///         return rouille::match_assets(&request, "public");
70///     }
71///
72///     // ...
73///     # panic!()
74/// });
75/// ```
76///
77/// In this example, a request made to `/static/test.txt` will return the file
78/// `public/test.txt` if it exists.
79///
80pub fn match_assets<P: ?Sized>(request: &Request, path: &P) -> Response
81where
82    P: AsRef<Path>,
83{
84    let path = path.as_ref();
85    let path = match path.canonicalize() {
86        Ok(p) => p,
87        Err(_) => return Response::empty_404(),
88    };
89
90    // The potential location of the file on the disk.
91    let potential_file = {
92        // Clippy erroneously identifies this transform as a redundant clone
93        #[allow(clippy::redundant_clone)]
94        let mut path = path.to_path_buf();
95        for component in request.url().split('/') {
96            path.push(component);
97        }
98        path
99    };
100
101    // We try to canonicalize the file. If this fails, then the file doesn't exist.
102    let potential_file = match potential_file.canonicalize() {
103        Ok(f) => f,
104        Err(_) => return Response::empty_404(),
105    };
106
107    // Check that we're still within `path`. This should eliminate security issues with
108    // requests like `GET /../private_file`.
109    if !potential_file.starts_with(path) {
110        return Response::empty_404();
111    }
112
113    // Check that it's a file and not a directory.
114    match fs::metadata(&potential_file) {
115        Ok(ref m) if m.is_file() => (),
116        _ => return Response::empty_404(),
117    };
118
119    let extension = potential_file.extension().and_then(|s| s.to_str());
120
121    let file = match fs::File::open(&potential_file) {
122        Ok(f) => f,
123        Err(_) => return Response::empty_404(),
124    };
125
126    let now = time::OffsetDateTime::now_local().unwrap_or_else(|_| time::OffsetDateTime::now_utc());
127    let etag: String = (fs::metadata(&potential_file)
128        .map(|meta| filetime::FileTime::from_last_modification_time(&meta).unix_seconds() as u64)
129        .unwrap_or(now.nanosecond() as u64)
130        ^ 0xd3f4_0305_c9f8_e911_u64)
131        .to_string();
132
133    Response::from_file(extension_to_mime_impl(extension), file)
134        .with_etag(request, etag)
135        .with_public_cache(3600) // TODO: is this a good idea? what if the file is private?
136}
137
138/// Returns the mime type of a file based on its extension, or `application/octet-stream` if the
139/// extension is unknown.
140#[inline]
141pub fn extension_to_mime(extension: &str) -> &'static str {
142    extension_to_mime_impl(Some(extension))
143}
144
145/// Returns the mime type of a file based on its extension.
146fn extension_to_mime_impl(extension: Option<&str>) -> &'static str {
147    // List taken from https://github.com/cybergeek94/mime_guess/blob/master/src/mime_types.rs,
148    // itself taken from a dead link.
149    match extension {
150        Some("323") => "text/h323; charset=utf8",
151        Some("3g2") => "video/3gpp2",
152        Some("3gp") => "video/3gpp",
153        Some("3gp2") => "video/3gpp2",
154        Some("3gpp") => "video/3gpp",
155        Some("7z") => "application/x-7z-compressed",
156        Some("aa") => "audio/audible",
157        Some("aac") => "audio/aac",
158        Some("aaf") => "application/octet-stream",
159        Some("aax") => "audio/vnd.audible.aax",
160        Some("ac3") => "audio/ac3",
161        Some("aca") => "application/octet-stream",
162        Some("accda") => "application/msaccess.addin",
163        Some("accdb") => "application/msaccess",
164        Some("accdc") => "application/msaccess.cab",
165        Some("accde") => "application/msaccess",
166        Some("accdr") => "application/msaccess.runtime",
167        Some("accdt") => "application/msaccess",
168        Some("accdw") => "application/msaccess.webapplication",
169        Some("accft") => "application/msaccess.ftemplate",
170        Some("acx") => "application/internet-property-stream",
171        Some("addin") => "application/xml",
172        Some("ade") => "application/msaccess",
173        Some("adobebridge") => "application/x-bridge-url",
174        Some("adp") => "application/msaccess",
175        Some("adt") => "audio/vnd.dlna.adts",
176        Some("adts") => "audio/aac",
177        Some("afm") => "application/octet-stream",
178        Some("ai") => "application/postscript",
179        Some("aif") => "audio/x-aiff",
180        Some("aifc") => "audio/aiff",
181        Some("aiff") => "audio/aiff",
182        Some("air") => "application/vnd.adobe.air-application-installer-package+zip",
183        Some("amc") => "application/x-mpeg",
184        Some("application") => "application/x-ms-application",
185        Some("art") => "image/x-jg",
186        Some("asa") => "application/xml",
187        Some("asax") => "application/xml",
188        Some("ascx") => "application/xml",
189        Some("asd") => "application/octet-stream",
190        Some("asf") => "video/x-ms-asf",
191        Some("ashx") => "application/xml",
192        Some("asi") => "application/octet-stream",
193        Some("asm") => "text/plain; charset=utf8",
194        Some("asmx") => "application/xml",
195        Some("aspx") => "application/xml",
196        Some("asr") => "video/x-ms-asf",
197        Some("asx") => "video/x-ms-asf",
198        Some("atom") => "application/atom+xml",
199        Some("au") => "audio/basic",
200        Some("avi") => "video/x-msvideo",
201        Some("axs") => "application/olescript",
202        Some("bas") => "text/plain; charset=utf8",
203        Some("bcpio") => "application/x-bcpio",
204        Some("bin") => "application/octet-stream",
205        Some("bmp") => "image/bmp",
206        Some("c") => "text/plain; charset=utf8",
207        Some("cab") => "application/octet-stream",
208        Some("caf") => "audio/x-caf",
209        Some("calx") => "application/vnd.ms-office.calx",
210        Some("cat") => "application/vnd.ms-pki.seccat",
211        Some("cc") => "text/plain; charset=utf8",
212        Some("cd") => "text/plain; charset=utf8",
213        Some("cdda") => "audio/aiff",
214        Some("cdf") => "application/x-cdf",
215        Some("cer") => "application/x-x509-ca-cert",
216        Some("chm") => "application/octet-stream",
217        Some("class") => "application/x-java-applet",
218        Some("clp") => "application/x-msclip",
219        Some("cmx") => "image/x-cmx",
220        Some("cnf") => "text/plain; charset=utf8",
221        Some("cod") => "image/cis-cod",
222        Some("config") => "application/xml",
223        Some("contact") => "text/x-ms-contact; charset=utf8",
224        Some("coverage") => "application/xml",
225        Some("cpio") => "application/x-cpio",
226        Some("cpp") => "text/plain; charset=utf8",
227        Some("crd") => "application/x-mscardfile",
228        Some("crl") => "application/pkix-crl",
229        Some("crt") => "application/x-x509-ca-cert",
230        Some("cs") => "text/plain; charset=utf8",
231        Some("csdproj") => "text/plain; charset=utf8",
232        Some("csh") => "application/x-csh",
233        Some("csproj") => "text/plain; charset=utf8",
234        Some("css") => "text/css; charset=utf8",
235        Some("csv") => "text/csv; charset=utf8",
236        Some("cur") => "application/octet-stream",
237        Some("cxx") => "text/plain; charset=utf8",
238        Some("dat") => "application/octet-stream",
239        Some("datasource") => "application/xml",
240        Some("dbproj") => "text/plain; charset=utf8",
241        Some("dcr") => "application/x-director",
242        Some("def") => "text/plain; charset=utf8",
243        Some("deploy") => "application/octet-stream",
244        Some("der") => "application/x-x509-ca-cert",
245        Some("dgml") => "application/xml",
246        Some("dib") => "image/bmp",
247        Some("dif") => "video/x-dv",
248        Some("dir") => "application/x-director",
249        Some("disco") => "application/xml",
250        Some("dll") => "application/x-msdownload",
251        Some("dll.config") => "application/xml",
252        Some("dlm") => "text/dlm; charset=utf8",
253        Some("doc") => "application/msword",
254        Some("docm") => "application/vnd.ms-word.document.macroEnabled.12",
255        Some("docx") => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
256        Some("dot") => "application/msword",
257        Some("dotm") => "application/vnd.ms-word.template.macroEnabled.12",
258        Some("dotx") => "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
259        Some("dsp") => "application/octet-stream",
260        Some("dsw") => "text/plain; charset=utf8",
261        Some("dtd") => "application/xml",
262        Some("dtsConfig") => "application/xml",
263        Some("dv") => "video/x-dv",
264        Some("dvi") => "application/x-dvi",
265        Some("dwf") => "drawing/x-dwf",
266        Some("dwp") => "application/octet-stream",
267        Some("dxr") => "application/x-director",
268        Some("eml") => "message/rfc822",
269        Some("emz") => "application/octet-stream",
270        Some("eot") => "application/vnd.ms-fontobject",
271        Some("eps") => "application/postscript",
272        Some("etl") => "application/etl",
273        Some("etx") => "text/x-setext; charset=utf8",
274        Some("evy") => "application/envoy",
275        Some("exe") => "application/octet-stream",
276        Some("exe.config") => "application/xml",
277        Some("fdf") => "application/vnd.fdf",
278        Some("fif") => "application/fractals",
279        Some("filters") => "Application/xml",
280        Some("fla") => "application/octet-stream",
281        Some("flr") => "x-world/x-vrml",
282        Some("flv") => "video/x-flv",
283        Some("fsscript") => "application/fsharp-script",
284        Some("fsx") => "application/fsharp-script",
285        Some("generictest") => "application/xml",
286        Some("gif") => "image/gif",
287        Some("group") => "text/x-ms-group; charset=utf8",
288        Some("gsm") => "audio/x-gsm",
289        Some("gtar") => "application/x-gtar",
290        Some("gz") => "application/x-gzip",
291        Some("h") => "text/plain; charset=utf8",
292        Some("hdf") => "application/x-hdf",
293        Some("hdml") => "text/x-hdml; charset=utf8",
294        Some("hhc") => "application/x-oleobject",
295        Some("hhk") => "application/octet-stream",
296        Some("hhp") => "application/octet-stream",
297        Some("hlp") => "application/winhlp",
298        Some("hpp") => "text/plain; charset=utf8",
299        Some("hqx") => "application/mac-binhex40",
300        Some("hta") => "application/hta",
301        Some("htc") => "text/x-component; charset=utf8",
302        Some("htm") => "text/html; charset=utf8",
303        Some("html") => "text/html; charset=utf8",
304        Some("htt") => "text/webviewhtml; charset=utf8",
305        Some("hxa") => "application/xml",
306        Some("hxc") => "application/xml",
307        Some("hxd") => "application/octet-stream",
308        Some("hxe") => "application/xml",
309        Some("hxf") => "application/xml",
310        Some("hxh") => "application/octet-stream",
311        Some("hxi") => "application/octet-stream",
312        Some("hxk") => "application/xml",
313        Some("hxq") => "application/octet-stream",
314        Some("hxr") => "application/octet-stream",
315        Some("hxs") => "application/octet-stream",
316        Some("hxt") => "text/html; charset=utf8",
317        Some("hxv") => "application/xml",
318        Some("hxw") => "application/octet-stream",
319        Some("hxx") => "text/plain; charset=utf8",
320        Some("i") => "text/plain; charset=utf8",
321        Some("ico") => "image/x-icon",
322        Some("ics") => "application/octet-stream",
323        Some("idl") => "text/plain; charset=utf8",
324        Some("ief") => "image/ief",
325        Some("iii") => "application/x-iphone",
326        Some("inc") => "text/plain; charset=utf8",
327        Some("inf") => "application/octet-stream",
328        Some("inl") => "text/plain; charset=utf8",
329        Some("ins") => "application/x-internet-signup",
330        Some("ipa") => "application/x-itunes-ipa",
331        Some("ipg") => "application/x-itunes-ipg",
332        Some("ipproj") => "text/plain; charset=utf8",
333        Some("ipsw") => "application/x-itunes-ipsw",
334        Some("iqy") => "text/x-ms-iqy; charset=utf8",
335        Some("isp") => "application/x-internet-signup",
336        Some("ite") => "application/x-itunes-ite",
337        Some("itlp") => "application/x-itunes-itlp",
338        Some("itms") => "application/x-itunes-itms",
339        Some("itpc") => "application/x-itunes-itpc",
340        Some("ivf") => "video/x-ivf",
341        Some("jar") => "application/java-archive",
342        Some("java") => "application/octet-stream",
343        Some("jck") => "application/liquidmotion",
344        Some("jcz") => "application/liquidmotion",
345        Some("jfif") => "image/pjpeg",
346        Some("jnlp") => "application/x-java-jnlp-file",
347        Some("jpb") => "application/octet-stream",
348        Some("jpe") => "image/jpeg",
349        Some("jpeg") => "image/jpeg",
350        Some("jpg") => "image/jpeg",
351        Some("js") => "application/javascript",
352        Some("json") => "application/json",
353        Some("jsx") => "text/jscript; charset=utf8",
354        Some("jsxbin") => "text/plain; charset=utf8",
355        Some("latex") => "application/x-latex",
356        Some("library-ms") => "application/windows-library+xml",
357        Some("lit") => "application/x-ms-reader",
358        Some("loadtest") => "application/xml",
359        Some("lpk") => "application/octet-stream",
360        Some("lsf") => "video/x-la-asf",
361        Some("lst") => "text/plain; charset=utf8",
362        Some("lsx") => "video/x-la-asf",
363        Some("lzh") => "application/octet-stream",
364        Some("m13") => "application/x-msmediaview",
365        Some("m14") => "application/x-msmediaview",
366        Some("m1v") => "video/mpeg",
367        Some("m2t") => "video/vnd.dlna.mpeg-tts",
368        Some("m2ts") => "video/vnd.dlna.mpeg-tts",
369        Some("m2v") => "video/mpeg",
370        Some("m3u") => "audio/x-mpegurl",
371        Some("m3u8") => "audio/x-mpegurl",
372        Some("m4a") => "audio/m4a",
373        Some("m4b") => "audio/m4b",
374        Some("m4p") => "audio/m4p",
375        Some("m4r") => "audio/x-m4r",
376        Some("m4v") => "video/x-m4v",
377        Some("mac") => "image/x-macpaint",
378        Some("mak") => "text/plain; charset=utf8",
379        Some("man") => "application/x-troff-man",
380        Some("manifest") => "application/x-ms-manifest",
381        Some("map") => "text/plain; charset=utf8",
382        Some("master") => "application/xml",
383        Some("mda") => "application/msaccess",
384        Some("mdb") => "application/x-msaccess",
385        Some("mde") => "application/msaccess",
386        Some("mdp") => "application/octet-stream",
387        Some("me") => "application/x-troff-me",
388        Some("mfp") => "application/x-shockwave-flash",
389        Some("mht") => "message/rfc822",
390        Some("mhtml") => "message/rfc822",
391        Some("mid") => "audio/mid",
392        Some("midi") => "audio/mid",
393        Some("mix") => "application/octet-stream",
394        Some("mk") => "text/plain; charset=utf8",
395        Some("mmf") => "application/x-smaf",
396        Some("mno") => "application/xml",
397        Some("mny") => "application/x-msmoney",
398        Some("mod") => "video/mpeg",
399        Some("mov") => "video/quicktime",
400        Some("movie") => "video/x-sgi-movie",
401        Some("mp2") => "video/mpeg",
402        Some("mp2v") => "video/mpeg",
403        Some("mp3") => "audio/mpeg",
404        Some("mp4") => "video/mp4",
405        Some("mp4v") => "video/mp4",
406        Some("mpa") => "video/mpeg",
407        Some("mpe") => "video/mpeg",
408        Some("mpeg") => "video/mpeg",
409        Some("mpf") => "application/vnd.ms-mediapackage",
410        Some("mpg") => "video/mpeg",
411        Some("mpp") => "application/vnd.ms-project",
412        Some("mpv2") => "video/mpeg",
413        Some("mqv") => "video/quicktime",
414        Some("ms") => "application/x-troff-ms",
415        Some("msi") => "application/octet-stream",
416        Some("mso") => "application/octet-stream",
417        Some("mts") => "video/vnd.dlna.mpeg-tts",
418        Some("mtx") => "application/xml",
419        Some("mvb") => "application/x-msmediaview",
420        Some("mvc") => "application/x-miva-compiled",
421        Some("mxp") => "application/x-mmxp",
422        Some("nc") => "application/x-netcdf",
423        Some("nsc") => "video/x-ms-asf",
424        Some("nws") => "message/rfc822",
425        Some("ocx") => "application/octet-stream",
426        Some("oda") => "application/oda",
427        Some("odc") => "text/x-ms-odc; charset=utf8",
428        Some("odh") => "text/plain; charset=utf8",
429        Some("odl") => "text/plain; charset=utf8",
430        Some("odp") => "application/vnd.oasis.opendocument.presentation",
431        Some("ods") => "application/oleobject",
432        Some("odt") => "application/vnd.oasis.opendocument.text",
433        Some("ogg") => "application/ogg",
434        Some("one") => "application/onenote",
435        Some("onea") => "application/onenote",
436        Some("onepkg") => "application/onenote",
437        Some("onetmp") => "application/onenote",
438        Some("onetoc") => "application/onenote",
439        Some("onetoc2") => "application/onenote",
440        Some("orderedtest") => "application/xml",
441        Some("osdx") => "application/opensearchdescription+xml",
442        Some("otf") => "application/x-font-opentype",
443        Some("p10") => "application/pkcs10",
444        Some("p12") => "application/x-pkcs12",
445        Some("p7b") => "application/x-pkcs7-certificates",
446        Some("p7c") => "application/pkcs7-mime",
447        Some("p7m") => "application/pkcs7-mime",
448        Some("p7r") => "application/x-pkcs7-certreqresp",
449        Some("p7s") => "application/pkcs7-signature",
450        Some("pbm") => "image/x-portable-bitmap",
451        Some("pcast") => "application/x-podcast",
452        Some("pct") => "image/pict",
453        Some("pcx") => "application/octet-stream",
454        Some("pcz") => "application/octet-stream",
455        Some("pdf") => "application/pdf",
456        Some("pfb") => "application/octet-stream",
457        Some("pfm") => "application/octet-stream",
458        Some("pfx") => "application/x-pkcs12",
459        Some("pgm") => "image/x-portable-graymap",
460        Some("pic") => "image/pict",
461        Some("pict") => "image/pict",
462        Some("pkgdef") => "text/plain; charset=utf8",
463        Some("pkgundef") => "text/plain; charset=utf8",
464        Some("pko") => "application/vnd.ms-pki.pko",
465        Some("pls") => "audio/scpls",
466        Some("pma") => "application/x-perfmon",
467        Some("pmc") => "application/x-perfmon",
468        Some("pml") => "application/x-perfmon",
469        Some("pmr") => "application/x-perfmon",
470        Some("pmw") => "application/x-perfmon",
471        Some("png") => "image/png",
472        Some("pnm") => "image/x-portable-anymap",
473        Some("pnt") => "image/x-macpaint",
474        Some("pntg") => "image/x-macpaint",
475        Some("pnz") => "image/png",
476        Some("pot") => "application/vnd.ms-powerpoint",
477        Some("potm") => "application/vnd.ms-powerpoint.template.macroEnabled.12",
478        Some("potx") => "application/vnd.openxmlformats-officedocument.presentationml.template",
479        Some("ppa") => "application/vnd.ms-powerpoint",
480        Some("ppam") => "application/vnd.ms-powerpoint.addin.macroEnabled.12",
481        Some("ppm") => "image/x-portable-pixmap",
482        Some("pps") => "application/vnd.ms-powerpoint",
483        Some("ppsm") => "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
484        Some("ppsx") => "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
485        Some("ppt") => "application/vnd.ms-powerpoint",
486        Some("pptm") => "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
487        Some("pptx") => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
488        Some("prf") => "application/pics-rules",
489        Some("prm") => "application/octet-stream",
490        Some("prx") => "application/octet-stream",
491        Some("ps") => "application/postscript",
492        Some("psc1") => "application/PowerShell",
493        Some("psd") => "application/octet-stream",
494        Some("psess") => "application/xml",
495        Some("psm") => "application/octet-stream",
496        Some("psp") => "application/octet-stream",
497        Some("pub") => "application/x-mspublisher",
498        Some("pwz") => "application/vnd.ms-powerpoint",
499        Some("qht") => "text/x-html-insertion; charset=utf8",
500        Some("qhtm") => "text/x-html-insertion; charset=utf8",
501        Some("qt") => "video/quicktime",
502        Some("qti") => "image/x-quicktime",
503        Some("qtif") => "image/x-quicktime",
504        Some("qtl") => "application/x-quicktimeplayer",
505        Some("qxd") => "application/octet-stream",
506        Some("ra") => "audio/x-pn-realaudio",
507        Some("ram") => "audio/x-pn-realaudio",
508        Some("rar") => "application/octet-stream",
509        Some("ras") => "image/x-cmu-raster",
510        Some("rat") => "application/rat-file",
511        Some("rc") => "text/plain; charset=utf8",
512        Some("rc2") => "text/plain; charset=utf8",
513        Some("rct") => "text/plain; charset=utf8",
514        Some("rdlc") => "application/xml",
515        Some("resx") => "application/xml",
516        Some("rf") => "image/vnd.rn-realflash",
517        Some("rgb") => "image/x-rgb",
518        Some("rgs") => "text/plain; charset=utf8",
519        Some("rm") => "application/vnd.rn-realmedia",
520        Some("rmi") => "audio/mid",
521        Some("rmp") => "application/vnd.rn-rn_music_package",
522        Some("roff") => "application/x-troff",
523        Some("rpm") => "audio/x-pn-realaudio-plugin",
524        Some("rqy") => "text/x-ms-rqy; charset=utf8",
525        Some("rtf") => "application/rtf",
526        Some("rtx") => "text/richtext; charset=utf8",
527        Some("ruleset") => "application/xml",
528        Some("s") => "text/plain; charset=utf8",
529        Some("safariextz") => "application/x-safari-safariextz",
530        Some("scd") => "application/x-msschedule",
531        Some("sct") => "text/scriptlet; charset=utf8",
532        Some("sd2") => "audio/x-sd2",
533        Some("sdp") => "application/sdp",
534        Some("sea") => "application/octet-stream",
535        Some("searchConnector-ms") => "application/windows-search-connector+xml",
536        Some("setpay") => "application/set-payment-initiation",
537        Some("setreg") => "application/set-registration-initiation",
538        Some("settings") => "application/xml",
539        Some("sfnt") => "application/font-sfnt",
540        Some("sgimb") => "application/x-sgimb",
541        Some("sgml") => "text/sgml; charset=utf8",
542        Some("sh") => "application/x-sh",
543        Some("shar") => "application/x-shar",
544        Some("shtml") => "text/html; charset=utf8",
545        Some("sit") => "application/x-stuffit",
546        Some("sitemap") => "application/xml",
547        Some("skin") => "application/xml",
548        Some("sldm") => "application/vnd.ms-powerpoint.slide.macroEnabled.12",
549        Some("sldx") => "application/vnd.openxmlformats-officedocument.presentationml.slide",
550        Some("slk") => "application/vnd.ms-excel",
551        Some("sln") => "text/plain; charset=utf8",
552        Some("slupkg-ms") => "application/x-ms-license",
553        Some("smd") => "audio/x-smd",
554        Some("smi") => "application/octet-stream",
555        Some("smx") => "audio/x-smd",
556        Some("smz") => "audio/x-smd",
557        Some("snd") => "audio/basic",
558        Some("snippet") => "application/xml",
559        Some("snp") => "application/octet-stream",
560        Some("sol") => "text/plain; charset=utf8",
561        Some("sor") => "text/plain; charset=utf8",
562        Some("spc") => "application/x-pkcs7-certificates",
563        Some("spl") => "application/futuresplash",
564        Some("src") => "application/x-wais-source",
565        Some("srf") => "text/plain; charset=utf8",
566        Some("ssisdeploymentmanifest") => "application/xml",
567        Some("ssm") => "application/streamingmedia",
568        Some("sst") => "application/vnd.ms-pki.certstore",
569        Some("stl") => "application/vnd.ms-pki.stl",
570        Some("sv4cpio") => "application/x-sv4cpio",
571        Some("sv4crc") => "application/x-sv4crc",
572        Some("svc") => "application/xml",
573        Some("svg") => "image/svg+xml",
574        Some("swf") => "application/x-shockwave-flash",
575        Some("t") => "application/x-troff",
576        Some("tar") => "application/x-tar",
577        Some("tcl") => "application/x-tcl",
578        Some("testrunconfig") => "application/xml",
579        Some("testsettings") => "application/xml",
580        Some("tex") => "application/x-tex",
581        Some("texi") => "application/x-texinfo",
582        Some("texinfo") => "application/x-texinfo",
583        Some("tgz") => "application/x-compressed",
584        Some("thmx") => "application/vnd.ms-officetheme",
585        Some("thn") => "application/octet-stream",
586        Some("tif") => "image/tiff",
587        Some("tiff") => "image/tiff",
588        Some("tlh") => "text/plain; charset=utf8",
589        Some("tli") => "text/plain; charset=utf8",
590        Some("toc") => "application/octet-stream",
591        Some("tr") => "application/x-troff",
592        Some("trm") => "application/x-msterminal",
593        Some("trx") => "application/xml",
594        Some("ts") => "video/vnd.dlna.mpeg-tts",
595        Some("tsv") => "text/tab-separated-values; charset=utf8",
596        Some("ttf") => "application/x-font-ttf",
597        Some("tts") => "video/vnd.dlna.mpeg-tts",
598        Some("txt") => "text/plain; charset=utf8",
599        Some("u32") => "application/octet-stream",
600        Some("uls") => "text/iuls; charset=utf8",
601        Some("user") => "text/plain; charset=utf8",
602        Some("ustar") => "application/x-ustar",
603        Some("vb") => "text/plain; charset=utf8",
604        Some("vbdproj") => "text/plain; charset=utf8",
605        Some("vbk") => "video/mpeg",
606        Some("vbproj") => "text/plain; charset=utf8",
607        Some("vbs") => "text/vbscript; charset=utf8",
608        Some("vcf") => "text/x-vcard; charset=utf8",
609        Some("vcproj") => "Application/xml",
610        Some("vcs") => "text/plain; charset=utf8",
611        Some("vcxproj") => "Application/xml",
612        Some("vddproj") => "text/plain; charset=utf8",
613        Some("vdp") => "text/plain; charset=utf8",
614        Some("vdproj") => "text/plain; charset=utf8",
615        Some("vdx") => "application/vnd.ms-visio.viewer",
616        Some("vml") => "application/xml",
617        Some("vscontent") => "application/xml",
618        Some("vsct") => "application/xml",
619        Some("vsd") => "application/vnd.visio",
620        Some("vsi") => "application/ms-vsi",
621        Some("vsix") => "application/vsix",
622        Some("vsixlangpack") => "application/xml",
623        Some("vsixmanifest") => "application/xml",
624        Some("vsmdi") => "application/xml",
625        Some("vspscc") => "text/plain; charset=utf8",
626        Some("vss") => "application/vnd.visio",
627        Some("vsscc") => "text/plain; charset=utf8",
628        Some("vssettings") => "application/xml",
629        Some("vssscc") => "text/plain; charset=utf8",
630        Some("vst") => "application/vnd.visio",
631        Some("vstemplate") => "application/xml",
632        Some("vsto") => "application/x-ms-vsto",
633        Some("vsw") => "application/vnd.visio",
634        Some("vsx") => "application/vnd.visio",
635        Some("vtx") => "application/vnd.visio",
636        Some("wasm") => "application/wasm",
637        Some("wav") => "audio/wav",
638        Some("wave") => "audio/wav",
639        Some("wax") => "audio/x-ms-wax",
640        Some("wbk") => "application/msword",
641        Some("wbmp") => "image/vnd.wap.wbmp",
642        Some("wcm") => "application/vnd.ms-works",
643        Some("wdb") => "application/vnd.ms-works",
644        Some("wdp") => "image/vnd.ms-photo",
645        Some("webarchive") => "application/x-safari-webarchive",
646        Some("webtest") => "application/xml",
647        Some("wiq") => "application/xml",
648        Some("wiz") => "application/msword",
649        Some("wks") => "application/vnd.ms-works",
650        Some("wlmp") => "application/wlmoviemaker",
651        Some("wlpginstall") => "application/x-wlpg-detect",
652        Some("wlpginstall3") => "application/x-wlpg3-detect",
653        Some("wm") => "video/x-ms-wm",
654        Some("wma") => "audio/x-ms-wma",
655        Some("wmd") => "application/x-ms-wmd",
656        Some("wmf") => "application/x-msmetafile",
657        Some("wml") => "text/vnd.wap.wml; charset=utf8",
658        Some("wmlc") => "application/vnd.wap.wmlc",
659        Some("wmls") => "text/vnd.wap.wmlscript; charset=utf8",
660        Some("wmlsc") => "application/vnd.wap.wmlscriptc",
661        Some("wmp") => "video/x-ms-wmp",
662        Some("wmv") => "video/x-ms-wmv",
663        Some("wmx") => "video/x-ms-wmx",
664        Some("wmz") => "application/x-ms-wmz",
665        Some("woff") => "application/font-woff",
666        Some("woff2") => "application/font-woff2",
667        Some("wpl") => "application/vnd.ms-wpl",
668        Some("wps") => "application/vnd.ms-works",
669        Some("wri") => "application/x-mswrite",
670        Some("wrl") => "x-world/x-vrml",
671        Some("wrz") => "x-world/x-vrml",
672        Some("wsc") => "text/scriptlet; charset=utf8",
673        Some("wsdl") => "application/xml",
674        Some("wvx") => "video/x-ms-wvx",
675        Some("x") => "application/directx",
676        Some("xaf") => "x-world/x-vrml",
677        Some("xaml") => "application/xaml+xml",
678        Some("xap") => "application/x-silverlight-app",
679        Some("xbap") => "application/x-ms-xbap",
680        Some("xbm") => "image/x-xbitmap",
681        Some("xdr") => "text/plain; charset=utf8",
682        Some("xht") => "application/xhtml+xml",
683        Some("xhtml") => "application/xhtml+xml",
684        Some("xla") => "application/vnd.ms-excel",
685        Some("xlam") => "application/vnd.ms-excel.addin.macroEnabled.12",
686        Some("xlc") => "application/vnd.ms-excel",
687        Some("xld") => "application/vnd.ms-excel",
688        Some("xlk") => "application/vnd.ms-excel",
689        Some("xll") => "application/vnd.ms-excel",
690        Some("xlm") => "application/vnd.ms-excel",
691        Some("xls") => "application/vnd.ms-excel",
692        Some("xlsb") => "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
693        Some("xlsm") => "application/vnd.ms-excel.sheet.macroEnabled.12",
694        Some("xlsx") => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
695        Some("xlt") => "application/vnd.ms-excel",
696        Some("xltm") => "application/vnd.ms-excel.template.macroEnabled.12",
697        Some("xltx") => "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
698        Some("xlw") => "application/vnd.ms-excel",
699        Some("xml") => "application/xml",
700        Some("xmta") => "application/xml",
701        Some("xof") => "x-world/x-vrml",
702        Some("xoml") => "text/plain; charset=utf8",
703        Some("xpm") => "image/x-xpixmap",
704        Some("xps") => "application/vnd.ms-xpsdocument",
705        Some("xrm-ms") => "application/xml",
706        Some("xsc") => "application/xml",
707        Some("xsd") => "application/xml",
708        Some("xsf") => "application/xml",
709        Some("xsl") => "application/xml",
710        Some("xslt") => "application/xslt+xml",
711        Some("xsn") => "application/octet-stream",
712        Some("xss") => "application/xml",
713        Some("xtp") => "application/octet-stream",
714        Some("xwd") => "image/x-xwindowdump",
715        Some("z") => "application/x-compress",
716        Some("zip") => "application/zip",
717        _ => "application/octet-stream",
718    }
719}