-
Notifications
You must be signed in to change notification settings - Fork 1
/
Headers.cpp
120 lines (86 loc) · 1.59 KB
/
Headers.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <Headers.h>
namespace HTTP {
Headers::Headers() :
type_(REQUEST),
curlHeaders_(NULL)
{
}
Headers::Headers(Headers::Type type) :
type_(type),
curlHeaders_(NULL)
{
}
Headers::~Headers()
{
clear();
}
bool
Headers::isSet(const std::string & name)
{
HeaderMap::iterator iter = headers_.find(name);
return iter != headers_.end();
}
std::string
Headers::get(const std::string & name)
{
HeaderMap::iterator iter = headers_.find(name);
if (iter != headers_.end()) {
return iter->second;
}
else {
return "";
}
}
std::string
Headers::operator[](const std::string & name)
{
return get(name);
}
void
Headers::set(const std::string & name, const std::string & value)
{
headers_.insert( StringPair(name, value) );
std::string nameValue = name;
nameValue += ": ";
nameValue += value;
if (type_ == REQUEST) {
curlHeaders_ = curl_slist_append(curlHeaders_, nameValue.c_str());
}
}
void
Headers::set(const std::string & name)
{
headers_.insert( StringPair(name, "") );
if (type_ == REQUEST) {
curlHeaders_ = curl_slist_append(curlHeaders_, (name + ";").c_str());
}
}
void
Headers::clear()
{
if (curlHeaders_) {
curl_slist_free_all(curlHeaders_);
curlHeaders_ = NULL;
}
headers_.clear();
}
unsigned int
Headers::size()
{
return headers_.size();
}
Headers::const_iterator
Headers::begin() const
{
return headers_.begin();
}
Headers::const_iterator
Headers::end() const
{
return headers_.end();
}
const struct curl_slist * Headers::getCurlHeaders() const
{
return curlHeaders_;
}
}