2222#include < algorithm>
2323#include < map>
2424#include < memory>
25- #include < regex>
25+ // Disabling lint error on regex (the only reason it errors is because the Chromium team prefers google/re2)
26+ #include < regex> // NOLINT [build/c++11]
2627#include < sstream>
2728#include < stdexcept>
2829#include < string>
3132#include " httpserver/details/http_endpoint.hpp"
3233#include " httpserver/http_utils.hpp"
3334
34- using namespace std ;
35+ using std::string;
36+ using std::vector;
3537
36- namespace httpserver
37- {
38+ namespace httpserver {
3839
39- namespace details
40- {
40+ namespace details {
4141
42- using namespace http ;
43-
44- http_endpoint::~http_endpoint ()
45- {
42+ http_endpoint::~http_endpoint () {
4643}
4744
48- http_endpoint::http_endpoint
49- (
50- const string& url,
51- bool family,
52- bool registration,
53- bool use_regex
54- ):
45+ http_endpoint::http_endpoint (const string& url, bool family, bool registration, bool use_regex):
5546 family_url (family),
56- reg_compiled (false )
57- {
58- if (use_regex && !registration)
59- {
47+ reg_compiled (false ) {
48+ if (use_regex && !registration) {
6049 throw std::invalid_argument (" Cannot use regex if not during registration" );
6150 }
6251
@@ -69,24 +58,20 @@ http_endpoint::http_endpoint
6958 url_complete = url;
7059#endif
7160
72- if (url_complete[url_complete.size () - 1 ] == ' /' )
73- {
61+ if (url_complete[url_complete.size () - 1 ] == ' /' ) {
7462 url_complete = url_complete.substr (0 , url_complete.size () - 1 );
7563 }
7664
77- if (url_complete[0 ] != ' /' )
78- {
65+ if (url_complete[0 ] != ' /' ) {
7966 url_complete = " /" + url_complete;
8067 }
8168
82- parts = http_utils::tokenize_url (url);
69+ parts = httpserver::http:: http_utils::tokenize_url (url);
8370 string buffered;
8471 bool first = true ;
8572
86- for (unsigned int i = 0 ; i < parts.size (); i++)
87- {
88- if (!registration)
89- {
73+ for (unsigned int i = 0 ; i < parts.size (); i++) {
74+ if (!registration) {
9075 url_normalized += (first ? " " : " /" ) + parts[i];
9176 first = false ;
9277
@@ -95,24 +80,21 @@ http_endpoint::http_endpoint
9580 continue ;
9681 }
9782
98- if ((parts[i] != " " ) && (parts[i][0 ] != ' {' ))
99- {
100- if (first)
101- {
83+ if ((parts[i] != " " ) && (parts[i][0 ] != ' {' )) {
84+ if (first) {
10285 url_normalized = (parts[i][0 ] == ' ^' ? " " : url_normalized) + parts[i];
10386 first = false ;
104- }
105- else
106- {
87+ } else {
10788 url_normalized += " /" + parts[i];
10889 }
10990 url_pieces.push_back (parts[i]);
11091
11192 continue ;
11293 }
11394
114- if ((parts[i].size () < 3 ) || (parts[i][0 ] != ' {' ) || (parts[i][parts[i].size () - 1 ] != ' }' ))
95+ if ((parts[i].size () < 3 ) || (parts[i][0 ] != ' {' ) || (parts[i][parts[i].size () - 1 ] != ' }' )) {
11596 throw std::invalid_argument (" Bad URL format" );
97+ }
11698
11799 std::string::size_type bar = parts[i].find_first_of (' |' );
118100 url_pars.push_back (parts[i].substr (1 , bar != string::npos ? bar - 1 : parts[i].size () - 2 ));
@@ -125,15 +107,11 @@ http_endpoint::http_endpoint
125107 url_pieces.push_back (parts[i]);
126108 }
127109
128- if (use_regex)
129- {
110+ if (use_regex) {
130111 url_normalized += " $" ;
131- try
132- {
112+ try {
133113 re_url_normalized = std::regex (url_normalized, std::regex::extended | std::regex::icase | std::regex::nosubs);
134- }
135- catch (std::regex_error& e)
136- {
114+ } catch (std::regex_error& e) {
137115 throw std::invalid_argument (" Not a valid regex in URL: " + url_normalized);
138116 }
139117 reg_compiled = true ;
@@ -148,12 +126,10 @@ http_endpoint::http_endpoint(const http_endpoint& h):
148126 chunk_positions (h.chunk_positions),
149127 re_url_normalized (h.re_url_normalized),
150128 family_url (h.family_url),
151- reg_compiled (h.reg_compiled)
152- {
129+ reg_compiled (h.reg_compiled) {
153130}
154131
155- http_endpoint& http_endpoint::operator =(const http_endpoint& h)
156- {
132+ http_endpoint& http_endpoint::operator =(const http_endpoint& h) {
157133 url_complete = h.url_complete ;
158134 url_normalized = h.url_normalized ;
159135 family_url = h.family_url ;
@@ -165,30 +141,26 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h)
165141 return *this ;
166142}
167143
168- bool http_endpoint::operator <(const http_endpoint& b) const
169- {
144+ bool http_endpoint::operator <(const http_endpoint& b) const {
170145 COMPARATOR (url_normalized, b.url_normalized , std::toupper);
171146}
172147
173- bool http_endpoint::match (const http_endpoint& url) const
174- {
148+ bool http_endpoint::match (const http_endpoint& url) const {
175149 if (!reg_compiled) throw std::invalid_argument (" Cannot run match. Regex suppressed." );
176150
177- if (!family_url || url.url_pieces .size () < url_pieces.size ())
178- {
151+ if (!family_url || url.url_pieces .size () < url_pieces.size ()) {
179152 return regex_match (url.url_complete , re_url_normalized);
180153 }
181154
182155 string nn = " /" ;
183156 bool first = true ;
184- for (unsigned int i = 0 ; i < url_pieces.size (); i++)
185- {
157+ for (unsigned int i = 0 ; i < url_pieces.size (); i++) {
186158 nn += (first ? " " : " /" ) + url.url_pieces [i];
187159 first = false ;
188160 }
189161 return regex_match (nn, re_url_normalized);
190162}
191163
192- };
164+ }; // namespace details
193165
194- };
166+ }; // namespace httpserver
0 commit comments