| 297 | } |
| 298 | |
| 299 | bool parse_request(const std::shared_ptr<Request> &request) const { |
| 300 | std::string line; |
| 301 | getline(request->content, line); |
| 302 | size_t method_end; |
| 303 | if((method_end=line.find(' '))!=std::string::npos) { |
| 304 | size_t path_end; |
| 305 | if((path_end=line.find(' ', method_end+1))!=std::string::npos) { |
| 306 | request->method=line.substr(0, method_end); |
| 307 | request->path=line.substr(method_end+2, path_end-method_end-2); |
| 308 | |
| 309 | size_t protocol_end; |
| 310 | if((protocol_end=line.find('/', path_end+1))!=std::string::npos) { |
| 311 | if(line.compare(path_end+1, protocol_end-path_end-1, "HTTP")!=0) |
| 312 | return false; |
| 313 | request->http_version=line.substr(protocol_end+1, line.size()-protocol_end-2); |
| 314 | } |
| 315 | else |
| 316 | return false; |
| 317 | |
| 318 | getline(request->content, line); |
| 319 | size_t param_end; |
| 320 | while((param_end=line.find(':'))!=std::string::npos) { |
| 321 | size_t value_start=param_end+1; |
| 322 | if((value_start)<line.size()) { |
| 323 | if(line[value_start]==' ') |
| 324 | value_start++; |
| 325 | if(value_start<line.size()) |
| 326 | request->header.emplace(line.substr(0, param_end), line.substr(value_start, line.size()-value_start-1)); |
| 327 | } |
| 328 | |
| 329 | getline(request->content, line); |
| 330 | } |
| 331 | } |
| 332 | else |
| 333 | return false; |
| 334 | } |
| 335 | else |
| 336 | return false; |
| 337 | return true; |
| 338 | } |
| 339 | |
| 340 | void find_resource(const std::shared_ptr<socket_type> &socket, const std::shared_ptr<Request> &request) { |
| 341 | //Upgrade connection |
no test coverage detected