forked from etr/libhttpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_request.cpp
More file actions
183 lines (163 loc) · 6.04 KB
/
http_request.cpp
File metadata and controls
183 lines (163 loc) · 6.04 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
This file is part of libhttpserver
Copyright (C) 2011 Sebastiano Merlino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "http_utils.hpp"
#include "http_request.hpp"
#include "string_utilities.hpp"
using namespace std;
namespace httpserver
{
//REQUEST
void http_request::set_method(const std::string& method)
{
string_utilities::to_upper_copy(method, this->method);
}
bool http_request::check_digest_auth(const std::string& realm, const std::string& password, int nonce_timeout, bool& reload_nonce) const
{
int val = MHD_digest_auth_check(underlying_connection, realm.c_str(), digested_user.c_str(), password.c_str(), nonce_timeout);
if(val == MHD_INVALID_NONCE)
{
reload_nonce = true;
return false;
}
else if(val == MHD_NO)
{
reload_nonce = false;
return false;
}
reload_nonce = false;
return true;
}
const std::vector<std::pair<std::string, std::string> > http_request::get_headers() const
{
std::vector<std::pair<std::string, std::string> > to_ret;
std::map<std::string, std::string, header_comparator>::const_iterator it;
for(it = headers.begin(); it != headers.end(); ++it)
#ifdef USE_CPP_ZEROX
to_ret.push_back(std::make_pair((*it).first,(*it).second));
#else
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
#endif
return to_ret;
}
size_t http_request::get_headers(std::vector<std::pair<std::string, std::string> >& result) const
{
std::map<std::string, std::string, header_comparator>::const_iterator it;
for(it = headers.begin(); it != headers.end(); ++it)
#ifdef USE_CPP_ZEROX
result.push_back(std::make_pair((*it).first,(*it).second));
#else
result.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
#endif
return result.size();
}
#ifndef SWIG
size_t http_request::get_headers(std::map<std::string, std::string, header_comparator>& result) const
{
result = this->headers;
return result.size();
}
#endif
const std::vector<std::pair<std::string, std::string> > http_request::get_footers() const
{
std::vector<std::pair<std::string, std::string> > to_ret;
std::map<std::string, std::string, header_comparator>::const_iterator it;
for(it = footers.begin(); it != footers.end(); ++it)
#ifdef USE_CPP_ZEROX
to_ret.push_back(std::make_pair((*it).first,(*it).second));
#else
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
#endif
return to_ret;
}
size_t http_request::get_footers(std::vector<std::pair<std::string, std::string> >& result) const
{
std::map<std::string, std::string, header_comparator>::const_iterator it;
for(it = footers.begin(); it != footers.end(); ++it)
#ifdef USE_CPP_ZEROX
result.push_back(std::make_pair((*it).first,(*it).second));
#else
result.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
#endif
return result.size();
}
#ifndef SWIG
size_t http_request::get_footers(std::map<std::string, std::string, header_comparator>& result) const
{
result = this->footers;
return result.size();
}
#endif
const std::vector<std::pair<std::string, std::string> > http_request::get_cookies() const
{
std::vector<std::pair<std::string, std::string> > to_ret;
std::map<std::string, std::string, header_comparator>::const_iterator it;
for(it = cookies.begin(); it != cookies.end(); ++it)
#ifdef USE_CPP_ZEROX
to_ret.push_back(std::make_pair((*it).first,(*it).second));
#else
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
#endif
return to_ret;
}
size_t http_request::get_cookies(std::vector<std::pair<std::string, std::string> >& result) const
{
std::map<std::string, std::string, header_comparator>::const_iterator it;
for(it = cookies.begin(); it != cookies.end(); ++it)
#ifdef USE_CPP_ZEROX
result.push_back(std::make_pair((*it).first,(*it).second));
#else
result.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
#endif
return result.size();
}
#ifndef SWIG
size_t http_request::get_cookies(std::map<std::string, std::string, header_comparator>& result) const
{
result = this->cookies;
return result.size();
}
#endif
const std::vector<std::pair<std::string, std::string> > http_request::get_args() const
{
std::vector<std::pair<std::string, std::string> > to_ret;
std::map<std::string, std::string, arg_comparator>::const_iterator it;
for(it = args.begin(); it != args.end(); ++it)
#ifdef USE_CPP_ZEROX
to_ret.push_back(std::make_pair((*it).first,(*it).second));
#else
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
#endif
return to_ret;
}
size_t http_request::get_args(std::vector<std::pair<std::string, std::string> >& result) const
{
std::map<std::string, std::string, header_comparator>::const_iterator it;
for(it = args.begin(); it != args.end(); ++it)
#ifdef USE_CPP_ZEROX
result.push_back(std::make_pair((*it).first,(*it).second));
#else
result.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
#endif
return result.size();
}
#ifndef SWIG
size_t http_request::get_args(std::map<std::string, std::string, arg_comparator>& result) const
{
result = this->args;
return result.size();
}
#endif
};