-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHost.h
83 lines (60 loc) · 1.9 KB
/
Host.h
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
76
77
78
79
80
81
82
#ifndef HOST_H
#define HOST_H
#include "elements.h"
#include "reader.h"
#include "HttpHeaders.h"
#include <string>
#include <map>
using namespace std;
class Host {
public:
Host(const json::Object& asJson) {
_port = (json::Number) asJson["port"];
_root = (json::String) asJson["root"];
_host = (json::String) asJson["host"];
json::Array mimes = (json::Array) asJson["mimetypes"];
json::Array::iterator itMime;
for(itMime = mimes.Begin(); itMime != mimes.End(); ++itMime) {
json::Object mime = *itMime;
_mimeTypes.insert(
pair<string, string>((json::String)mime["extention"], (json::String)mime["contenttype"])
);
}
}
~Host() {
}
void setRoot(string _root) {
this->_root = _root;
}
const string& getRoot() const {
return _root;
}
void setHost(string _hostname) {
this->_host = _hostname;
}
const string& getHost() const {
return _host;
}
void setPort(int _port) {
this->_port = _port;
}
const int& getPort() const {
return _port;
}
const string getMimeType(HttpHeaders& httpHeaders) {
string meh = httpHeaders.extension;
if(_mimeTypes.find(meh) != _mimeTypes.end()) {
return _mimeTypes[meh];
}
//cout << "mime not found" << endl;
// TODO: return something sane.
return "text/html";
}
private:
Host(const Host& orig) { }
int _port;
string _host;
string _root;
map<string, string> _mimeTypes;
};
#endif /* HOST_H */