Skip to content

Commit d3ed932

Browse files
author
Sebastiano Merlino
committed
Added some comments to http_endpoint and http_request
1 parent 2640c3a commit d3ed932

File tree

2 files changed

+132
-6
lines changed

2 files changed

+132
-6
lines changed

src/httpserver/http_endpoint.hpp

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ namespace httpserver
3030

3131
class webserver;
3232

33+
/**
34+
* Exception class throwed when a bad formatted http url is used
35+
**/
3336
class bad_http_endpoint : public std::exception
3437
{
38+
/**
39+
* Method used to see error details
40+
* @return a const char* containing the error message
41+
**/
3542
virtual const char* what() const throw()
3643
{
3744
return "Bad url format!";
@@ -81,10 +88,18 @@ class http_endpoint
8188
{
8289
return this->url_complete;
8390
}
91+
/**
92+
* Method used to get the complete endpoint url
93+
* @param result a string reference that will be filled with the url
94+
**/
8495
void get_url_complete(std::string& result) const
8596
{
8697
result = this->url_complete;
8798
}
99+
/**
100+
* Method used to find the size of the complete endpoint url
101+
* @return the size
102+
**/
88103
size_t get_url_complete_size() const
89104
{
90105
return this->url_complete.size();
@@ -110,11 +125,20 @@ class http_endpoint
110125
{
111126
return this->url_pieces;
112127
}
128+
/**
129+
* Method used to get all pieces of an url; considering an url splittet by '/'.
130+
* @param result a vector of strings to fill with url pieces.
131+
* @return the size of the vector in output
132+
**/
113133
size_t get_url_pieces(std::vector<std::string>& result) const
114134
{
115135
result = this->url_pieces;
116136
return result.size();
117137
}
138+
/**
139+
* Method used to get the number of pieces the url is composed of
140+
* @return the number of pieces
141+
**/
118142
size_t get_url_pieces_num() const
119143
{
120144
return this->url_pieces.size();
@@ -127,6 +151,11 @@ class http_endpoint
127151
{
128152
return this->chunk_positions;
129153
}
154+
/**
155+
* Method used to get indexes of all parameters inside url
156+
* @param result a vector to fill with ints indicating chunk positions
157+
* @return the size of the vector filled
158+
**/
130159
size_t get_chunk_positions(std::vector<int>& result) const
131160
{
132161
result = this->chunk_positions;
@@ -153,22 +182,43 @@ class http_endpoint
153182
* @param family boolean that indicates if the endpoint is a family endpoint.
154183
* A family endpoint is an endpoint that identifies a root and all its child like the same resource.
155184
* For example, if I identify "/path/" like a family endpoint and I associate to it the resource "A", also
156-
* "/path/to/res/" is automatically associated to resource "A".
185+
* "/path/to/res/" is automatically associated to resource "A". Default is false.
157186
* @param registration boolean that indicates to the system if this is an endpoint that need to be registered to a webserver
158-
* or it is simply an endpoint to be used for comparisons.
187+
* or it is simply an endpoint to be used for comparisons. Default is false.
188+
* @param use_regex boolean that indicates if regexes are checked or not. Default is true.
159189
**/
160190
http_endpoint(const std::string& url, bool family = false, bool registration = false, bool use_regex = true);
161191
/**
162-
* Destructor of the class. Essentially it frees the regex dinamically allocated pattern
192+
* The complete url extracted
163193
**/
164194
std::string url_complete;
195+
/**
196+
* The url standardized in order to use standard comparisons or regexes
197+
**/
165198
std::string url_modded;
199+
/**
200+
* Vector containing parameters extracted from url
201+
**/
166202
std::vector<std::string> url_pars;
203+
/**
204+
* Pieces the url can be splitted into (consider '/' as separator)
205+
**/
167206
std::vector<std::string> url_pieces;
207+
/**
208+
* Position of url pieces representing parameters
209+
**/
168210
std::vector<int> chunk_positions;
211+
/**
212+
* Regex used in comparisons
213+
**/
169214
regex_t re_url_modded;
170-
// boost::xpressive::sregex re_url_modded;
215+
/**
216+
* Boolean indicating wheter the endpoint represents a family
217+
**/
171218
bool family_url;
219+
/**
220+
* Boolean indicating if the regex is compiled
221+
**/
172222
bool reg_compiled;
173223
friend class webserver;
174224
};

src/httpserver/http_request.hpp

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,26 @@ class http_request
5555
{
5656
return this->user;
5757
}
58+
/**
59+
* Method used to get the username eventually passed through basic authentication.
60+
* @param result string that will be filled with the username
61+
**/
5862
void get_user(std::string& result) const
5963
{
6064
result = this->user;
6165
}
66+
/**
67+
* Method used to get the username extracted from a digest authentication
68+
* @return the username
69+
**/
6270
const std::string get_digested_user() const
6371
{
6472
return this->digested_user;
6573
}
74+
/**
75+
* Method used to get the username extracted from a digest authentication
76+
* @param result string that will be filled with the username
77+
**/
6678
void get_digested_user(std::string& result) const
6779
{
6880
result = this->digested_user;
@@ -75,6 +87,10 @@ class http_request
7587
{
7688
return this->pass;
7789
}
90+
/**
91+
* Method used to get the password eventually passed through basic authentication.
92+
* @param result string that will be filled with the password.
93+
**/
7894
void get_pass(std::string& result) const
7995
{
8096
result = this->pass;
@@ -87,6 +103,10 @@ class http_request
87103
{
88104
return this->path;
89105
}
106+
/**
107+
* Method used to get the path requested
108+
* @param result string that will be filled with the path.
109+
**/
90110
void get_path(std::string& result) const
91111
{
92112
result = this->path;
@@ -99,7 +119,12 @@ class http_request
99119
{
100120
return this->post_path;
101121
}
102-
int get_path_pieces(std::vector<std::string>& result) const
122+
/**
123+
* Method used to get all pieces of the path requested; considering an url splitted by '/'.
124+
* @param result vector of strings containing the path
125+
* @return the size of the vector filled
126+
**/
127+
size_t get_path_pieces(std::vector<std::string>& result) const
103128
{
104129
result = this->post_path;
105130
return result.size();
@@ -108,12 +133,13 @@ class http_request
108133
* Method used to obtain the size of path in terms of pieces; considering an url splitted by '/'.
109134
* @return an integer representing the number of pieces
110135
**/
111-
int get_path_pieces_size() const
136+
size_t get_path_pieces_size() const
112137
{
113138
return this->post_path.size();
114139
}
115140
/**
116141
* Method used to obtain a specified piece of the path; considering an url splitted by '/'.
142+
* @param index the index of the piece selected
117143
* @return the selected piece in form of string
118144
**/
119145
const std::string get_path_piece(int index) const
@@ -122,6 +148,12 @@ class http_request
122148
return this->post_path[index];
123149
return "";
124150
}
151+
/**
152+
* Method used to obtain a specified piece of the path; considering an url splitted by '/'.
153+
* @param index the index of the piece selected
154+
* @param result a string that will be filled with the piece found
155+
* @return the length of the piece found
156+
**/
125157
size_t get_path_piece(int index, std::string& result) const
126158
{
127159
if(((int)(this->post_path.size())) > index)
@@ -143,6 +175,10 @@ class http_request
143175
{
144176
return this->method;
145177
}
178+
/**
179+
* Method used to get the METHOD used to make the request.
180+
* @param result string that will be filled with the method.
181+
**/
146182
void get_method(std::string& result) const
147183
{
148184
result = this->method;
@@ -152,35 +188,75 @@ class http_request
152188
* @return a vector<pair<string,string> > containing all headers.
153189
**/
154190
const std::vector<std::pair<std::string, std::string> > get_headers() const;
191+
/**
192+
* Method used to get all headers passed with the request.
193+
* @param result a vector<pair<string, string> > that will be filled with all headers
194+
* @result the size of the vector
195+
**/
155196
size_t get_headers(std::vector<std::pair<std::string, std::string> >& result) const;
156197
#ifndef SWIG
198+
/**
199+
* Method used to get all headers passed with the request.
200+
* @param result a map<string, string> > that will be filled with all headers
201+
* @result the size of the map
202+
**/
157203
size_t get_headers(std::map<std::string, std::string, header_comparator>& result) const;
158204
#endif
159205
/**
160206
* Method used to get all footers passed with the request.
161207
* @return a vector<pair<string,string> > containing all footers.
162208
**/
163209
const std::vector<std::pair<std::string, std::string> > get_footers() const;
210+
/**
211+
* Method used to get all footers passed with the request.
212+
* @param result a vector<pair<string, string> > that will be filled with all footers
213+
* @result the size of the vector
214+
**/
164215
size_t get_footers(std::vector<std::pair<std::string, std::string> >& result) const;
165216
#ifndef SWIG
217+
/**
218+
* Method used to get all footers passed with the request.
219+
* @param result a map<string, string> > that will be filled with all footers
220+
* @result the size of the map
221+
**/
166222
size_t get_footers(std::map<std::string, std::string, header_comparator>& result) const;
167223
#endif
168224
/**
169225
* Method used to get all cookies passed with the request.
170226
* @return a vector<pair<string, string> > containing all cookies.
171227
**/
172228
const std::vector<std::pair<std::string, std::string> > get_cookies() const;
229+
/**
230+
* Method used to get all cookies passed with the request.
231+
* @param result a vector<pair<string, string> > that will be filled with all cookies
232+
* @result the size of the vector
233+
**/
173234
size_t get_cookies(std::vector<std::pair<std::string, std::string> >& result) const;
174235
#ifndef SWIG
236+
/**
237+
* Method used to get all cookies passed with the request.
238+
* @param result a map<string, string> > that will be filled with all cookies
239+
* @result the size of the map
240+
**/
175241
size_t get_cookies(std::map<std::string, std::string, header_comparator>& result) const;
176242
#endif
177243
/**
178244
* Method used to get all parameters passed with the request. Usually parameters are passed with DELETE or GET methods.
179245
* @return a map<string,string> containing all parameters.
180246
**/
181247
const std::vector<std::pair<std::string, std::string> > get_args() const;
248+
/**
249+
* Method used to get all args passed with the request.
250+
* @param result a vector<pair<string, string> > that will be filled with all args
251+
* @result the size of the vector
252+
**/
182253
size_t get_args(std::vector<std::pair<std::string, std::string> >& result) const;
183254
#ifndef SWIG
255+
/**
256+
* Method used to get all args passed with the request.
257+
* @param result a map<string, string> > that will be filled with all args
258+
* @result the size of the map
259+
**/
184260
size_t get_args(std::map<std::string, std::string, arg_comparator>& result) const;
185261
#endif
186262
/**

0 commit comments

Comments
 (0)