| 294 | } |
| 295 | |
| 296 | std::string Server::ReadRequestBody(struct mg_connection* conn, |
| 297 | const struct mg_request_info* request_info) { |
| 298 | LOG(TRACE) << "Entering Server::ReadRequestBody"; |
| 299 | |
| 300 | std::string request_body = ""; |
| 301 | int content_length = 0; |
| 302 | for (int header_index = 0; header_index < 64; ++header_index) { |
| 303 | if (request_info->http_headers[header_index].name == NULL) { |
| 304 | break; |
| 305 | } |
| 306 | std::string header_name(request_info->http_headers[header_index].name); |
| 307 | std::transform(header_name.begin(), |
| 308 | header_name.end(), |
| 309 | header_name.begin(), |
| 310 | ::tolower); |
| 311 | if (header_name.compare("content-length") == 0) { |
| 312 | content_length = atoi(request_info->http_headers[header_index].value); |
| 313 | break; |
| 314 | } |
| 315 | } |
| 316 | if (content_length != 0) { |
| 317 | std::vector<char> buffer(content_length + 1); |
| 318 | int bytes_read = 0; |
| 319 | while (bytes_read < content_length) { |
| 320 | bytes_read += mg_read(conn, |
| 321 | &buffer[bytes_read], |
| 322 | content_length - bytes_read); |
| 323 | } |
| 324 | buffer[content_length] = '\0'; |
| 325 | request_body.append(&buffer[0]); |
| 326 | } |
| 327 | |
| 328 | return request_body; |
| 329 | } |
| 330 | |
| 331 | std::string Server::DispatchCommand(const std::string& uri, |
| 332 | const std::string& http_verb, |
no test coverage detected