forked from ayoubelhioui/WebServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFormat.cpp
50 lines (46 loc) · 2.59 KB
/
getFormat.cpp
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
#include "webserver.hpp"
const char *get_mime_format(const char *type){
const char *last_dot = strrchr(type, '.');
if(last_dot == NULL)
return "";
if (strcmp(last_dot, ".css") == 0) return "text/css";
if (strcmp(last_dot, ".csv") == 0) return "text/csv";
if (strcmp(last_dot, ".gif") == 0) return "image/gif";
if (strcmp(last_dot, ".htm") == 0) return "text/html";
if (strcmp(last_dot, ".html") == 0) return "text/html";
if (strcmp(last_dot, ".ico") == 0) return "image/x-icon";
if (strcmp(last_dot, ".jpeg") == 0) return "image/jpeg";
if (strcmp(last_dot, ".jpg") == 0) return "image/jpeg";
if (strcmp(last_dot, ".js") == 0) return "application/javascript";
if (strcmp(last_dot, ".json") == 0) return "application/json";
if (strcmp(last_dot, ".png") == 0) return "image/png";
if (strcmp(last_dot, ".pdf") == 0) return "application/pdf";
if (strcmp(last_dot, ".svg") == 0) return "image/svg+xml";
if (strcmp(last_dot, ".txt") == 0) return "text/plain";
if (strcmp(last_dot, ".mp4") == 0) return "video/mp4";
if (strcmp(last_dot, ".cpp") == 0) return "text/x-c";
if (strcmp(last_dot, ".php") == 0) return "text/php";
return "application/octet-stream";
}
const char *get_real_format(const char *mime_type)
{
if (strcmp(mime_type, "text/css") == 0) return ".css";
if (strcmp(mime_type, "text/csv") == 0) return ".csv";
if (strcmp(mime_type, "image/gif") == 0) return ".gif";
if (strcmp(mime_type, "text/html") == 0) return ".html";
if (strcmp(mime_type, "text/html") == 0) return ".html";
if (strcmp(mime_type, "image/x-icon") == 0) return ".x-icon";
if (strcmp(mime_type, "image/jpeg") == 0) return ".jpeg";
if (strcmp(mime_type, "image/jpeg") == 0) return ".jpeg";
if (strcmp(mime_type, "application/javascript") == 0) return ".javascript";
if (strcmp(mime_type, "application/json") == 0) return ".json";
if (strcmp(mime_type, "image/png") == 0) return ".png";
if (strcmp(mime_type, "application/pdf") == 0) return ".pdf";
if (strcmp(mime_type, "image/svg+xml") == 0) return ".svg+xml";
if (strcmp(mime_type, "text/plain") == 0) return ".txt";
if (strcmp(mime_type, "video/mp4") == 0) return ".mp4";
if (strcmp(mime_type, "text/php") == 0) return ".php";
if (strcmp(mime_type, "application/x-httpd-php") == 0) return ".php";
if (strcmp(mime_type, "application/x-www-form-urlencoded") == 0) return ".php";
return "";
}