Skip to content

Commit 6944b25

Browse files
author
Sebastiano Merlino
committed
Merge branch 'master' of github.com:etr/libhttpserver
Conflicts: src/httpserver/http_request.hpp src/httpserver/http_response.hpp src/webserver.cpp
2 parents bc41052 + 6c79c5b commit 6944b25

File tree

5 files changed

+87
-72
lines changed

5 files changed

+87
-72
lines changed

src/http_request.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,53 @@ bool http_request::check_digest_auth(const std::string& realm, const std::string
4848
return true;
4949
}
5050

51+
const std::vector<std::pair<std::string, std::string> > http_request::get_headers() const
52+
{
53+
std::vector<std::pair<std::string, std::string> > to_ret;
54+
std::map<std::string, std::string, header_comparator>::const_iterator it;
55+
for(it = headers.begin(); it != headers.end(); it++)
56+
#ifdef USE_CPP_ZEROX
57+
to_ret.push_back(std::make_pair((*it).first,(*it).second));
58+
#else
59+
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
60+
#endif
61+
return to_ret;
62+
}
63+
const std::vector<std::pair<std::string, std::string> > http_request::get_footers() const
64+
{
65+
std::vector<std::pair<std::string, std::string> > to_ret;
66+
std::map<std::string, std::string, header_comparator>::const_iterator it;
67+
for(it = footers.begin(); it != footers.end(); it++)
68+
#ifdef USE_CPP_ZEROX
69+
to_ret.push_back(std::make_pair((*it).first,(*it).second));
70+
#else
71+
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
72+
#endif
73+
return to_ret;
74+
}
75+
const std::vector<std::pair<std::string, std::string> > http_request::get_cookies() const
76+
{
77+
std::vector<std::pair<std::string, std::string> > to_ret;
78+
std::map<std::string, std::string, header_comparator>::const_iterator it;
79+
for(it = cookies.begin(); it != cookies.end(); it++)
80+
#ifdef USE_CPP_ZEROX
81+
to_ret.push_back(std::make_pair((*it).first,(*it).second));
82+
#else
83+
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
84+
#endif
85+
return to_ret;
86+
}
87+
const std::vector<std::pair<std::string, std::string> > http_request::get_args() const
88+
{
89+
std::vector<std::pair<std::string, std::string> > to_ret;
90+
std::map<std::string, std::string, arg_comparator>::const_iterator it;
91+
for(it = args.begin(); it != args.end(); it++)
92+
#ifdef USE_CPP_ZEROX
93+
to_ret.push_back(std::make_pair((*it).first,(*it).second));
94+
#else
95+
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
96+
#endif
97+
return to_ret;
98+
}
99+
51100
};

src/http_response.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ using namespace std;
2828

2929
namespace httpserver
3030
{
31+
32+
const std::vector<std::pair<std::string, std::string> > http_response::get_headers()
33+
{
34+
std::vector<std::pair<std::string, std::string> > to_ret;
35+
std::map<std::string, std::string, header_comparator>::const_iterator it;
36+
for(it = headers.begin(); it != headers.end(); it++)
37+
#ifdef USE_CPP_ZEROX
38+
to_ret.push_back(std::make_pair((*it).first,(*it).second));
39+
#else
40+
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
41+
#endif
42+
return to_ret;
43+
}
44+
const std::vector<std::pair<std::string, std::string> > http_response::get_footers()
45+
{
46+
std::vector<std::pair<std::string, std::string> > to_ret;
47+
std::map<std::string, std::string, arg_comparator>::const_iterator it;
48+
for(it = footers.begin(); it != footers.end(); it++)
49+
#ifdef USE_CPP_ZEROX
50+
to_ret.push_back(std::make_pair((*it).first,(*it).second));
51+
#else
52+
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
53+
#endif
54+
return to_ret;
55+
}
3156
//RESPONSE
3257
http_file_response::http_file_response
3358
(

src/httpserver/http_request.hpp

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -140,66 +140,22 @@ class http_request
140140
* Method used to get all headers passed with the request.
141141
* @return a vector<pair<string,string> > containing all headers.
142142
**/
143-
const std::vector<std::pair<std::string, std::string> > get_headers() const
144-
{
145-
std::vector<std::pair<std::string, std::string> > to_ret;
146-
std::map<std::string, std::string, header_comparator>::const_iterator it;
147-
for(it = headers.begin(); it != headers.end(); it++)
148-
#ifdef USE_CPP_ZEROX
149-
to_ret.push_back(std::make_pair((*it).first,(*it).second));
150-
#else
151-
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
152-
#endif
153-
return to_ret;
154-
}
143+
const std::vector<std::pair<std::string, std::string> > get_headers() const;
155144
/**
156145
* Method used to get all footers passed with the request.
157146
* @return a vector<pair<string,string> > containing all footers.
158147
**/
159-
const std::vector<std::pair<std::string, std::string> > get_footers() const
160-
{
161-
std::vector<std::pair<std::string, std::string> > to_ret;
162-
std::map<std::string, std::string, header_comparator>::const_iterator it;
163-
for(it = footers.begin(); it != footers.end(); it++)
164-
#ifdef USE_CPP_ZEROX
165-
to_ret.push_back(std::make_pair((*it).first,(*it).second));
166-
#else
167-
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
168-
#endif
169-
return to_ret;
170-
}
148+
const std::vector<std::pair<std::string, std::string> > get_footers() const;
171149
/**
172150
* Method used to get all cookies passed with the request.
173151
* @return a vector<pair<string, string> > containing all cookies.
174152
**/
175-
const std::vector<std::pair<std::string, std::string> > get_cookies() const
176-
{
177-
std::vector<std::pair<std::string, std::string> > to_ret;
178-
std::map<std::string, std::string, header_comparator>::const_iterator it;
179-
for(it = cookies.begin(); it != cookies.end(); it++)
180-
#ifdef USE_CPP_ZEROX
181-
to_ret.push_back(std::make_pair((*it).first,(*it).second));
182-
#else
183-
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
184-
#endif
185-
return to_ret;
186-
}
153+
const std::vector<std::pair<std::string, std::string> > get_cookies() const;
187154
/**
188155
* Method used to get all parameters passed with the request. Usually parameters are passed with DELETE or GET methods.
189156
* @return a map<string,string> containing all parameters.
190157
**/
191-
const std::vector<std::pair<std::string, std::string> > get_args() const
192-
{
193-
std::vector<std::pair<std::string, std::string> > to_ret;
194-
std::map<std::string, std::string, arg_comparator>::const_iterator it;
195-
for(it = args.begin(); it != args.end(); it++)
196-
#ifdef USE_CPP_ZEROX
197-
to_ret.push_back(std::make_pair((*it).first,(*it).second));
198-
#else
199-
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
200-
#endif
201-
return to_ret;
202-
}
158+
const std::vector<std::pair<std::string, std::string> > get_args() const;
203159
/**
204160
* Method used to get a specific header passed with the request.
205161
* @param key the specific header to get the value from

src/httpserver/http_response.hpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -172,34 +172,12 @@ class http_response
172172
* Method used to get all headers passed with the request.
173173
* @return a map<string,string> containing all headers.
174174
**/
175-
const std::vector<std::pair<std::string, std::string> > get_headers()
176-
{
177-
std::vector<std::pair<std::string, std::string> > to_ret;
178-
std::map<std::string, std::string, header_comparator>::const_iterator it;
179-
for(it = headers.begin(); it != headers.end(); it++)
180-
#ifdef USE_CPP_ZEROX
181-
to_ret.push_back(std::make_pair((*it).first,(*it).second));
182-
#else
183-
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
184-
#endif
185-
return to_ret;
186-
}
175+
const std::vector<std::pair<std::string, std::string> > get_headers();
187176
/**
188177
* Method used to get all footers passed with the request.
189178
* @return a map<string,string> containing all footers.
190179
**/
191-
const std::vector<std::pair<std::string, std::string> > get_footers()
192-
{
193-
std::vector<std::pair<std::string, std::string> > to_ret;
194-
std::map<std::string, std::string, arg_comparator>::const_iterator it;
195-
for(it = footers.begin(); it != footers.end(); it++)
196-
#ifdef USE_CPP_ZEROX
197-
to_ret.push_back(std::make_pair((*it).first,(*it).second));
198-
#else
199-
to_ret.push_back(std::make_pair<std::string, std::string>((*it).first,(*it).second));
200-
#endif
201-
return to_ret;
202-
}
180+
const std::vector<std::pair<std::string, std::string> > get_footers();
203181
/**
204182
* Method used to set all headers of the response.
205183
* @param headers The headers key-value map to set for the response.

src/webserver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,13 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
651651
mr->dhr = &support_req;
652652
}
653653

654+
MHD_get_connection_values (connection, MHD_HEADER_KIND, &build_request_header, (void*) mr->dhr);
655+
MHD_get_connection_values (connection, MHD_FOOTER_KIND, &build_request_footer, (void*) mr->dhr);
656+
MHD_get_connection_values (connection, MHD_COOKIE_KIND, &build_request_cookie, (void*) mr->dhr);
657+
658+
mr->dhr->set_path(st_url);
659+
mr->dhr->set_method(method);
660+
654661
if ( 0 == strcmp(method, MHD_HTTP_METHOD_DELETE) ||
655662
0 == strcmp(method, MHD_HTTP_METHOD_GET) ||
656663
0 == strcmp(method, MHD_HTTP_METHOD_HEAD) ||

0 commit comments

Comments
 (0)