forked from nachaphon-phontree/TrustTunnelClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_header.cpp
More file actions
66 lines (57 loc) · 2.01 KB
/
http_header.cpp
File metadata and controls
66 lines (57 loc) · 2.01 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
#include "net/http_header.h"
#include "common/utils.h"
#include "vpn/utils.h"
namespace ag {
bool HttpHeaders::contains_field(std::string_view name) const {
return fields.end() != std::find_if(fields.begin(), fields.end(), [name](const HttpHeaderField &field) {
return case_equals(field.name, name);
});
}
std::optional<std::string_view> HttpHeaders::get_field(std::string_view name) const {
if (auto it = std::find_if(fields.begin(), fields.end(),
[name](const HttpHeaderField &field) {
return case_equals(field.name, name);
});
it != fields.end()) {
return it->value;
}
return std::nullopt;
}
void HttpHeaders::put_field(std::string name, std::string value) {
if (!name.empty() && name.front() == ':') {
if (case_equals(name, METHOD_PH_FIELD)) {
this->method = std::move(value);
return;
}
if (case_equals(name, SCHEME_PH_FIELD)) {
this->scheme = std::move(value);
return;
}
if (case_equals(name, AUTHORITY_PH_FIELD)) {
this->authority = std::move(value);
return;
}
if (case_equals(name, PATH_PH_FIELD)) {
this->path = std::move(value);
return;
}
if (case_equals(name, STATUS_PH_FIELD)) {
this->status_code = ag::utils::to_integer<int>(value).value_or(0);
return;
}
}
this->fields.emplace_back(std::move(name), std::move(value));
}
void HttpHeaders::remove_field(std::string_view name) {
fields.erase(std::remove_if(fields.begin(), fields.end(),
[name](const HttpHeaderField &f) {
return case_equals(f.name, name);
}),
fields.end());
}
HttpHeaderField::HttpHeaderField() = default;
HttpHeaderField::HttpHeaderField(std::string name, std::string value)
: name(std::move(name))
, value(std::move(value)) {
}
} // namespace ag