|
3 | 3 | import com.sun.net.httpserver.Headers; |
4 | 4 | import express.cookie.Cookie; |
5 | 5 |
|
6 | | -import java.io.UnsupportedEncodingException; |
| 6 | +import java.io.*; |
7 | 7 | import java.net.URI; |
8 | 8 | import java.net.URLDecoder; |
9 | 9 | import java.util.HashMap; |
|
13 | 13 |
|
14 | 14 | public class ExpressUtils { |
15 | 15 |
|
16 | | - private final static HashMap<String, String> CTS = new HashMap<>(); |
17 | | - |
18 | | - static { |
19 | | - CTS.put("aac", "audio/aac"); |
20 | | - CTS.put("abw", "application/x-abiword"); |
21 | | - CTS.put("arc", "application/octet-stream"); |
22 | | - CTS.put("avi", "video/x-msvideo"); |
23 | | - CTS.put("azw", "application/vnd.amazon.ebook"); |
24 | | - CTS.put("bin", "application/octet-stream"); |
25 | | - CTS.put("bz", "application/x-bzip"); |
26 | | - CTS.put("bz2", "application/x-bzip2"); |
27 | | - CTS.put("csh", "application/x-csh"); |
28 | | - CTS.put("css", "text/css"); |
29 | | - CTS.put("csv", "text/csv"); |
30 | | - CTS.put("doc", "application/msword"); |
31 | | - CTS.put("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
32 | | - CTS.put("eot", "application/vnd.ms-fontobject"); |
33 | | - CTS.put("epub", "application/epub+zip"); |
34 | | - CTS.put("gif", "image/gif"); |
35 | | - CTS.put("htm", "text/html"); |
36 | | - CTS.put("html", "text/html"); |
37 | | - CTS.put("ico", "image/x-icon"); |
38 | | - CTS.put("ics", "text/calendar"); |
39 | | - CTS.put("jar", "application/java-archive"); |
40 | | - CTS.put("jpeg", "image/jpeg"); |
41 | | - CTS.put("jpg", "image/jpeg"); |
42 | | - CTS.put("js", "application/javascript"); |
43 | | - CTS.put("json", "application/json"); |
44 | | - CTS.put("mid", "audio/midi"); |
45 | | - CTS.put("midi", "audio/midi"); |
46 | | - CTS.put("mpeg", "video/mpeg"); |
47 | | - CTS.put("mpkg", "application/vnd.apple.installer+xml"); |
48 | | - CTS.put("odp", "application/vnd.oasis.opendocument.presentation"); |
49 | | - CTS.put("ods", "application/vnd.oasis.opendocument.spreadsheet"); |
50 | | - CTS.put("odt", "application/vnd.oasis.opendocument.text"); |
51 | | - CTS.put("oga", "audio/ogg"); |
52 | | - CTS.put("ogv", "video/ogg"); |
53 | | - CTS.put("ogx", "application/ogg"); |
54 | | - CTS.put("otf", "font/otf"); |
55 | | - CTS.put("png", "image/png"); |
56 | | - CTS.put("pdf", "application/pdf"); |
57 | | - CTS.put("ppt", "application/vnd.ms-powerpoint"); |
58 | | - CTS.put("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"); |
59 | | - CTS.put("rar", "application/x-rar-compressed"); |
60 | | - CTS.put("rtf", "application/rtf"); |
61 | | - CTS.put("sh", "application/x-sh"); |
62 | | - CTS.put("svg", "image/svg+xml"); |
63 | | - CTS.put("swf", "application/x-shockwave-flash"); |
64 | | - CTS.put("tar", "application/x-tar"); |
65 | | - CTS.put("tif", "image/tiff"); |
66 | | - CTS.put("tiff", "image/tiff"); |
67 | | - CTS.put("ts", "application/typescript"); |
68 | | - CTS.put("ttf", "font/ttf"); |
69 | | - CTS.put("vsd", "application/vnd.visio"); |
70 | | - CTS.put("wav", "audio/x-wav"); |
71 | | - CTS.put("weba", "audio/webm"); |
72 | | - CTS.put("webm", "video/webm"); |
73 | | - CTS.put("webp", "image/webp"); |
74 | | - CTS.put("woff", "font/woff"); |
75 | | - CTS.put("woff2", "font/woff2"); |
76 | | - CTS.put("xhtml", "application/xhtml+xml"); |
77 | | - CTS.put("xls", "application/vnd.ms-excel"); |
78 | | - CTS.put("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
79 | | - CTS.put("xml", "application/xml"); |
80 | | - CTS.put("xul", "application/vnd.mozilla.xul+xml"); |
81 | | - CTS.put("zip", "application/zip"); |
82 | | - CTS.put("3gp", "video/3gpp"); |
83 | | - CTS.put("3g2", "video/3gpp2"); |
84 | | - CTS.put("7z", "application/x-7z-compressed"); |
85 | | - } |
86 | | - |
87 | 16 | public static HashMap<String, Cookie> parseCookies(Headers headers) { |
88 | 17 | HashMap<String, Cookie> cookieList = new HashMap<>(); |
89 | 18 | List<String> headerCookies = headers.get("Cookie"); |
@@ -127,7 +56,7 @@ public static HashMap<String, String> parseRawQuery(URI uri) { |
127 | 56 | } |
128 | 57 |
|
129 | 58 | public static String getContentType(String fileExtension) { |
130 | | - String ct = CTS.get(fileExtension); |
| 59 | + String ct = MIMETypes.get().get(fileExtension); |
131 | 60 |
|
132 | 61 | if (ct == null) |
133 | 62 | ct = "text/plain"; |
|
0 commit comments