@@ -84,7 +84,8 @@ We use a simple example to briefly introduce the use of this library. Consider t
84
84
85
85
int main () {
86
86
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 `\\.`
88
89
std::regex txt_regex("[a-z]+\\.txt");
89
90
for (const auto &fname: fnames)
90
91
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
186
187
template<typename SERVER_TYPE>
187
188
void start_server(SERVER_TYPE &server) {
188
189
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
190
192
server.resource["fill_your_reg_ex"]["GET"] = [](ostream& response, Request& request) {
191
193
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;
193
196
};
194
197
195
198
// peocess default GET request; anonymous function will be called if no other matches
196
199
// response files in folder web/
197
200
// 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
+ }
212
216
213
217
// (...)
214
218
};
0 commit comments