-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathRequest.cpp
More file actions
75 lines (54 loc) · 1.69 KB
/
Request.cpp
File metadata and controls
75 lines (54 loc) · 1.69 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
#include "Request.h"
namespace HttpServer
{
std::string Request::getHeader(const std::string &key) const {
auto it = headers.find(key);
return headers.end() != it ? it->second : std::string();
}
bool Request::isDataExists(const std::string &key) const {
return data.cend() != data.find(key);
}
std::string Request::getDataAsString(const std::string &key) const {
auto it = data.find(key);
return data.end() != it ? it->second : std::string();
}
std::vector<std::string> Request::getDataAsArray(const std::string &key) const
{
std::vector<std::string> arr;
size_t count = data.count(key);
if (count) {
auto range = data.equal_range(key);
arr.resize(count);
size_t i = 0;
for (auto it = range.first; it != range.second; ++it) {
arr[i++] = it->second;
}
}
return arr;
}
bool Request::isFileExists(const std::string &key) const {
return this->files.cend() != this->files.find(key);
}
Transfer::FileIncoming Request::getFile(const std::string &key) const {
auto const it = this->files.find(key);
return this->files.end() != it ? it->second : Transfer::FileIncoming();
}
std::vector<Transfer::FileIncoming> Request::getFilesAsArray(const std::string &key) const
{
std::vector<Transfer::FileIncoming> arr;
const size_t count = this->files.count(key);
if (count) {
auto const range = this->files.equal_range(key);
arr.resize(count);
size_t i = 0;
for (auto it = range.first; it != range.second; ++it) {
arr[i++] = it->second;
}
}
return arr;
}
std::string Request::getCookieAsString(const std::string &cookieName) const {
auto it = cookies.find(cookieName);
return cookies.end() != it ? it->second : std::string();
}
}