1818 USA
1919*/
2020
21- #include " http_endpoint.hpp"
21+ #include " details/ http_endpoint.hpp"
2222#include " http_utils.hpp"
2323#include " string_utilities.hpp"
2424
@@ -27,17 +27,20 @@ using namespace std;
2727namespace httpserver
2828{
2929
30+ namespace details
31+ {
32+
3033using namespace http ;
3134
32- webserver:: http_endpoint::~http_endpoint ()
35+ http_endpoint::~http_endpoint ()
3336{
3437 if (reg_compiled)
3538 {
36- regfree (&(this ->re_url_modded ));
39+ regfree (&(this ->re_url_normalized ));
3740 }
3841}
3942
40- webserver:: http_endpoint::http_endpoint
43+ http_endpoint::http_endpoint
4144(
4245 const string& url,
4346 bool family,
@@ -47,7 +50,7 @@ webserver::http_endpoint::http_endpoint
4750 family_url (family),
4851 reg_compiled (false )
4952{
50- this ->url_modded = use_regex ? " ^/" : " /" ;
53+ this ->url_normalized = use_regex ? " ^/" : " /" ;
5154 vector<string> parts;
5255
5356#ifdef CASE_INSENSITIVE
@@ -67,7 +70,7 @@ webserver::http_endpoint::http_endpoint
6770 {
6871 if (!registration)
6972 {
70- this ->url_modded += (first ? " " : " /" ) + parts[i];
73+ this ->url_normalized += (first ? " " : " /" ) + parts[i];
7174 first = false ;
7275
7376 this ->url_pieces .push_back (parts[i]);
@@ -79,12 +82,12 @@ webserver::http_endpoint::http_endpoint
7982 {
8083 if (first)
8184 {
82- this ->url_modded = (parts[i][0 ] == ' ^' ? " " : this ->url_modded ) + parts[i];
85+ this ->url_normalized = (parts[i][0 ] == ' ^' ? " " : this ->url_normalized ) + parts[i];
8386 first = false ;
8487 }
8588 else
8689 {
87- this ->url_modded += " /" + parts[i];
90+ this ->url_normalized += " /" + parts[i];
8891 }
8992 this ->url_pieces .push_back (parts[i]);
9093
@@ -96,7 +99,7 @@ webserver::http_endpoint::http_endpoint
9699
97100 std::string::size_type bar = parts[i].find_first_of (' |' );
98101 this ->url_pars .push_back (parts[i].substr (1 , bar != string::npos ? bar - 1 : parts[i].size () - 2 ));
99- this ->url_modded += (first ? " " : " /" ) + (bar != string::npos ? parts[i].substr (bar + 1 , parts[i].size () - bar - 2 ) : " ([^\\ /]+)" );
102+ this ->url_normalized += (first ? " " : " /" ) + (bar != string::npos ? parts[i].substr (bar + 1 , parts[i].size () - bar - 2 ) : " ([^\\ /]+)" );
100103
101104 first = false ;
102105
@@ -107,37 +110,37 @@ webserver::http_endpoint::http_endpoint
107110
108111 if (use_regex)
109112 {
110- this ->url_modded += " $" ;
111- regcomp (&(this ->re_url_modded ), url_modded .c_str (),
113+ this ->url_normalized += " $" ;
114+ regcomp (&(this ->re_url_normalized ), url_normalized .c_str (),
112115 REG_EXTENDED|REG_ICASE|REG_NOSUB
113116 );
114117 this ->reg_compiled = true ;
115118 }
116119}
117120
118- webserver:: http_endpoint::http_endpoint (const webserver:: http_endpoint& h):
121+ http_endpoint::http_endpoint (const http_endpoint& h):
119122 url_complete (h.url_complete),
120- url_modded (h.url_modded ),
123+ url_normalized (h.url_normalized ),
121124 url_pars (h.url_pars),
122125 url_pieces (h.url_pieces),
123126 chunk_positions (h.chunk_positions),
124127 family_url (h.family_url),
125128 reg_compiled (h.reg_compiled)
126129{
127130 if (this ->reg_compiled )
128- regcomp (&(this ->re_url_modded ), url_modded .c_str (),
131+ regcomp (&(this ->re_url_normalized ), url_normalized .c_str (),
129132 REG_EXTENDED|REG_ICASE|REG_NOSUB
130133 );
131134}
132135
133- webserver:: http_endpoint& webserver:: http_endpoint::operator =(const webserver:: http_endpoint& h)
136+ http_endpoint& http_endpoint::operator =(const http_endpoint& h)
134137{
135138 this ->url_complete = h.url_complete ;
136- this ->url_modded = h.url_modded ;
139+ this ->url_normalized = h.url_normalized ;
137140 this ->family_url = h.family_url ;
138141 this ->reg_compiled = h.reg_compiled ;
139142 if (this ->reg_compiled )
140- regcomp (&(this ->re_url_modded ), url_modded .c_str (),
143+ regcomp (&(this ->re_url_normalized ), url_normalized .c_str (),
141144 REG_EXTENDED|REG_ICASE|REG_NOSUB
142145 );
143146 this ->url_pars = h.url_pars ;
@@ -146,16 +149,16 @@ webserver::http_endpoint& webserver::http_endpoint::operator =(const webserver::
146149 return *this ;
147150}
148151
149- bool webserver:: http_endpoint::operator <(const webserver:: http_endpoint& b) const
152+ bool http_endpoint::operator <(const http_endpoint& b) const
150153{
151- COMPARATOR (this ->url_modded , b.url_modded , std::toupper);
154+ COMPARATOR (this ->url_normalized , b.url_normalized , std::toupper);
152155}
153156
154- bool webserver:: http_endpoint::match (const webserver:: http_endpoint& url) const
157+ bool http_endpoint::match (const http_endpoint& url) const
155158{
156159
157- if (!this ->family_url || url.url_pieces .size () < this ->url_pieces .size ())
158- return regexec (&(this ->re_url_modded ), url.url_complete .c_str (), 0 , NULL , 0 ) == 0 ;
160+ if (!this ->family_url || url.url_pieces .size () < this ->url_pieces .size ())
161+ return regexec (&(this ->re_url_normalized ), url.url_complete .c_str (), 0 , NULL , 0 ) == 0 ;
159162
160163 string nn = " /" ;
161164 bool first = true ;
@@ -164,8 +167,9 @@ bool webserver::http_endpoint::match(const webserver::http_endpoint& url) const
164167 nn += (first ? " " : " /" ) + url.url_pieces [i];
165168 first = false ;
166169 }
167- return regexec (&(this ->re_url_modded ), nn.c_str (), 0 , NULL , 0 ) == 0 ;
170+ return regexec (&(this ->re_url_normalized ), nn.c_str (), 0 , NULL , 0 ) == 0 ;
168171}
169172
170173};
171174
175+ };
0 commit comments