-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMimeTypes.cpp
More file actions
48 lines (40 loc) · 1.13 KB
/
Copy pathMimeTypes.cpp
File metadata and controls
48 lines (40 loc) · 1.13 KB
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
#include "MimeTypes.h"
#include <unordered_map>
using namespace std;
string MimeTypes::get(const string& filePath)
{
static const unordered_map<string, string> mimeTypes =
{
{".html", "text/html"},
{".css", "text/css"},
{".js", "application/javascript"},
{".png", "image/png"},
{".jpg", "image/jpeg"},
{".jpeg", "image/jpeg"},
{".svg", "image/svg+xml"},
{".ico", "image/x-icon"},
{".json", "application/json"},
{".txt", "text/plain"},
{".mp4", "video/mp4"},
{".mov", "video/quicktime"},
{".webm", "video/webm"},
{".mp3", "audio/mpeg"},
{".wav", "audio/wav"},
{".ogg", "audio/ogg"},
{".pdf", "application/pdf"},
{".woff", "font/woff"},
{".woff2", "font/woff2"}
};
size_t dot = filePath.find_last_of('.');
if (dot == string::npos)
{
return "application/octet-stream";
}
string extension = filePath.substr(dot);
auto it = mimeTypes.find(extension);
if (it != mimeTypes.end())
{
return it->second;
}
return "application/octet-stream";
}