Link v2.0
[link.git] / Source / Link.cpp
blob5ba01f7ff99b3c63c200d2592dfd3be74d7be5db
1 #include <Link.hpp>
2 #include <iostream>
4 std::string Link::Status(int status) {
5 switch (status) {
6 case 200: return "OK";
7 case 201: return "Created";
8 case 202: return "Accepted";
9 case 203: return "Non-Authoritative Information";
10 case 204: return "No Content";
11 case 205: return "Reset Content";
12 case 206: return "Partial Content";
13 case 300: return "Multiple Choices";
14 case 301: return "Moved Permanently";
15 case 302: return "Found";
16 case 303: return "See Other";
17 case 304: return "Not Modified";
18 case 305: return "Use Proxy";
19 case 307: return "Temporary Redirect";
20 case 400: return "Bad Request";
21 case 401: return "Unauthorized";
22 case 402: return "Payment Required";
23 case 403: return "Forbidden";
24 case 404: return "Not Found";
25 case 405: return "Method Not Allowed";
26 case 406: return "Not Acceptable";
27 case 407: return "Proxy Authentication Required";
28 case 408: return "Request Timeout";
29 case 409: return "Conflict";
30 case 410: return "Gone";
31 case 411: return "Length Required";
32 case 412: return "Precondition Failed";
33 case 413: return "Request Entity Too Large";
34 case 414: return "Request-URI Too Long";
35 case 415: return "Unsupported Media Type";
36 case 416: return "Requested Range Not Satisfiable";
37 case 417: return "Expectation Failed";
38 case 500: return "Internal Server Error";
39 case 501: return "Not Implemented";
40 case 502: return "Bad Gateway";
41 case 503: return "Service Unavailable";
42 case 504: return "Gateway Timeout";
43 case 505: return "HTTP Version Not Supported";
44 default: return "Unknown";
48 std::string Link::GetMIMEType(std::string path) {
49 // get the extension
50 std::string extension = path.substr(path.find_last_of(".") + 1);
51 // convert to lowercase
52 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
53 // return the MIME type
54 if (extension == "html" || extension == "htm") return "text/html";
55 if (extension == "css") return "text/css";
56 if (extension == "js") return "application/javascript";
57 if (extension == "json") return "application/json";
58 if (extension == "xml") return "application/xml";
59 if (extension == "png") return "image/png";
60 if (extension == "jpg" || extension == "jpeg") return "image/jpeg";
61 if (extension == "gif") return "image/gif";
62 if (extension == "svg") return "image/svg+xml";
63 if (extension == "ico") return "image/x-icon";
64 if (extension == "ttf") return "font/ttf";
65 if (extension == "otf") return "font/otf";
66 if (extension == "woff") return "font/woff";
67 if (extension == "woff2") return "font/woff2";
68 if (extension == "eot") return "font/eot";
69 if (extension == "mp3") return "audio/mpeg";
70 if (extension == "wav") return "audio/wav";
71 if (extension == "ogg") return "audio/ogg";
72 if (extension == "mp4") return "video/mp4";
73 if (extension == "webm") return "video/webm";
74 if (extension == "ogv") return "video/ogg";
75 if (extension == "pdf") return "application/pdf";
76 if (extension == "zip") return "application/zip";
77 if (extension == "rar") return "application/x-rar-compressed";
78 if (extension == "7z") return "application/x-7z-compressed";
79 if (extension == "doc") return "application/msword";
80 if (extension == "docx") return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
81 if (extension == "xls") return "application/vnd.ms-excel";
82 if (extension == "xlsx") return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
83 if (extension == "ppt") return "application/vnd.ms-powerpoint";
84 if (extension == "pptx") return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
85 if (extension == "exe") return "application/x-msdownload";
86 if (extension == "apk") return "application/vnd.android.package-archive";
87 if (extension == "ipa") return "application/octet-stream";
88 if (extension == "deb") return "application/x-debian-package";
89 if (extension == "rpm") return "application/x-redhat-package-manager";
90 if (extension == "tar") return "application/x-tar";
91 if (extension == "gz") return "application/gzip";
92 if (extension == "bz2") return "application/x-bzip2";
93 if (extension == "xz") return "application/x-xz";
94 if (extension == "bin") return "application/octet-stream";
95 if (extension == "iso") return "application/octet-stream";
96 if (extension == "dmg") return "application/octet-stream";
97 if (extension == "txt") return "text/plain";
98 if (extension == "rtf") return "text/rtf";
99 if (extension == "md") return "text/markdown";
100 if (extension == "csv") return "text/csv";
101 if (extension == "ics") return "text/calendar";
102 if (extension == "yml") return "text/yaml";
103 if (extension == "yaml") return "text/yaml";
104 if (extension == "php") return "text/x-php";
105 if (extension == "c") return "text/x-c";
106 if (extension == "cpp") return "text/x-c";
107 if (extension == "h") return "text/x-c";
108 if (extension == "hpp") return "text/x-c";
109 if (extension == "java") return "text/x-java-source";
110 if (extension == "py") return "text/x-python";
111 if (extension == "sh") return "text/x-shellscript";
112 if (extension == "bat") return "text/x-shellscript";
113 if (extension == "rb") return "text/x-ruby";
114 if (extension == "swift") return "text/x-swift";
115 if (extension == "go") return "text/x-go";
116 if (extension == "pl") return "text/x-perl";
117 if (extension == "sql") return "text/x-sql";
118 if (extension == "lua") return "text/x-lua";
119 if (extension == "diff") return "text/x-diff";
120 if (extension == "patch") return "text/x-diff";
121 if (extension == "conf") return "text/x-config";
122 if (extension == "ini") return "text/x-ini";
123 if (extension == "log") return "text/x-log";
124 if (extension == "rtx") return "text/richtext";
125 if (extension == "tsv") return "text/tab-separated-values";
126 if (extension == "jad") return "text/vnd.sun.j2me.app-descriptor";
127 if (extension == "wml") return "text/vnd.wap.wml";
128 if (extension == "wmls") return "text/vnd.wap.wmlscript";
129 if (extension == "vtt") return "text/vtt";
130 if (extension == "htc") return "text/x-component";
131 if (extension == "f4v") return "video/x-f4v";
132 if (extension == "flv") return "video/x-flv";
133 if (extension == "m4v") return "video/x-m4v";
134 if (extension == "mkv") return "video/x-matroska";
135 if (extension == "mov") return "video/quicktime";
136 if (extension == "mp2") return "video/mpeg";
137 if (extension == "mpg") return "video/mpeg";
138 if (extension == "mpeg") return "video/mpeg";
139 if (extension == "mpe") return "video/mpeg";
140 if (extension == "m2v") return "video/mpeg";
141 if (extension == "m4v") return "video/mpeg";
142 if (extension == "3gp") return "video/3gpp";
143 if (extension == "3g2") return "video/3gpp2";
144 if (extension == "asf") return "video/x-ms-asf";
145 if (extension == "asx") return "video/x-ms-asf";
146 return "application/octet-stream";