@@ -84,7 +84,8 @@ We use a simple example to briefly introduce the use of this library. Consider t
8484
8585int main () {
8686 std::string fnames[] = {"foo.txt", "bar.txt", "test", "a0.txt", "AAA.txt"};
87- // In C++, `\` will be used as an escape character in the string. In order for `\.` to be passed as a regular expression, it is necessary to perform second escaping of `\`, thus we have `\\.`
87+ // In C++, `\` will be used as an escape character in the string. In order for `\.`
88+ // to be passed as a regular expression, it is necessary to perform second escaping of `\`, thus we have `\\.`
8889 std::regex txt_regex("[a-z]+\\.txt");
8990 for (const auto &fname: fnames)
9091 std::cout << fname << ": " << std::regex_match(fname, txt_regex) << std::endl;
@@ -186,29 +187,32 @@ Please implement the member functions `start()` and `parse_request`. Enable serv
186187template<typename SERVER_TYPE>
187188void start_server(SERVER_TYPE &server) {
188189
189- // process GET request for /match/[digit+numbers], e.g. GET request is /match/abc123, will return abc123
190+ // process GET request for /match/[digit+numbers], e.g.
191+ // GET request is /match/abc123, will return abc123
190192 server.resource["fill_your_reg_ex"]["GET"] = [](ostream& response, Request& request) {
191193 string number=request.path_match[1];
192- response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number;
194+ response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length()
195+ << "\r\n\r\n" << number;
193196 };
194197
195198 // peocess default GET request; anonymous function will be called if no other matches
196199 // response files in folder web/
197200 // default: index.html
198- server.default_resource["fill_your_reg_ex"]["GET"] = [](ostream& response, Request& request) {
199- string filename = "www/";
200-
201- string path = request.path_match[1];
202-
203- // forbidden use `..` access content outside folder web/
204- size_t last_pos = path.rfind(".");
205- size_t current_pos = 0;
206- size_t pos;
207- while((pos=path.find('.', current_pos)) != string::npos && pos != last_pos) {
208- current_pos = pos;
209- path.erase(pos, 1);
210- last_pos--;
211- }
201+ server.default_resource["fill_your_reg_ex"]["GET"] =
202+ [](ostream& response, Request& request) {
203+ string filename = "www/";
204+
205+ string path = request.path_match[1];
206+
207+ // forbidden use `..` access content outside folder web/
208+ size_t last_pos = path.rfind(".");
209+ size_t current_pos = 0;
210+ size_t pos;
211+ while((pos=path.find('.', current_pos)) != string::npos && pos != last_pos) {
212+ current_pos = pos;
213+ path.erase(pos, 1);
214+ last_pos--;
215+ }
212216
213217 // (...)
214218 };
0 commit comments