-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHttpMediaTypeDatabase.cc
More file actions
75 lines (63 loc) · 2.23 KB
/
HttpMediaTypeDatabase.cc
File metadata and controls
75 lines (63 loc) · 2.23 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright (C) 2021 Frank Mertens.
*
* Distribution and use is allowed under the terms of the GNU General Public License version 3
* (see CoreComponents/LICENSE-gpl-3.0).
*
*/
#include <cc/HttpMediaTypeDatabase>
#include <cc/Casefree>
#include <cc/Prefix>
#include <cc/Map>
namespace cc {
struct HttpMediaTypeDatabase::State: public Object::State
{
State()
{
mediaTypeByFileSuffix_.insert("xhtml", "application/xhtml+xml");
mediaTypeByFileSuffix_.insert("css", "text/css");
mediaTypeByFileSuffix_.insert("js", "text/javascript");
mediaTypeByFileSuffix_.insert("svg", "image/svg+xml");
mediaTypeByFileSuffix_.insert("webp", "image/webp");
mediaTypeByContentPrefix_.insert("<!DOCTYPE html", "text/html");
mediaTypeByContentPrefix_.insert("<html", "text/html");
mediaTypeByContentPrefix_.insert("<?xml", "application/xml");
mediaTypeByContentPrefix_.insert("<svg", "image/svg+xml");
mediaTypeByContentPrefix_.insert("\377\330", "image/jpeg");
mediaTypeByContentPrefix_.insert("\211PNG", "image/png");
mediaTypeByContentPrefix_.insert("II*\0", "image/tiff");
mediaTypeByContentPrefix_.insert("MM*\0", "image/tiff");
mediaTypeByContentPrefix_.insert("GIF87a", "image/gif");
mediaTypeByContentPrefix_.insert("GIF89a", "image/gif");
}
String lookup(const String &path, const String &content) const
{
String value;
if (path != "") {
String suffix = path.fileSuffix();
if (suffix != "") {
if (mediaTypeByFileSuffix_.lookup(suffix, &value))
return value;
}
}
if (mediaTypeByContentPrefix_.lookup(Prefix{content}, &value)) {
return value;
}
return value;
}
Map<Casefree<String>, String> mediaTypeByFileSuffix_;
Map<String, String> mediaTypeByContentPrefix_;
};
HttpMediaTypeDatabase::HttpMediaTypeDatabase()
{
initOnce<State>();
}
String HttpMediaTypeDatabase::lookup(const String &path, const String &content) const
{
return me().lookup(path, content);
}
const HttpMediaTypeDatabase::State &HttpMediaTypeDatabase::me() const
{
return Object::me.as<State>();
}
} // namespace cc