The standard HTTP Status codes are implemented below. Chrome uses OK, See Other, Not Found, Method Not Allowed, and Internal Error. Internal Error, HTTP 500, is used as a catch all for any issue not covered in the JSON protocol.
| 534 | // Internal Error, HTTP 500, is used as a catch all for any issue |
| 535 | // not covered in the JSON protocol. |
| 536 | void Server::SendHttpOk(struct mg_connection* connection, |
| 537 | const struct mg_request_info* request_info, |
| 538 | const std::string& body, |
| 539 | const std::string& content_type) { |
| 540 | LOG(TRACE) << "Entering Server::SendHttpOk"; |
| 541 | |
| 542 | std::string body_to_send = body + "\r\n"; |
| 543 | |
| 544 | std::ostringstream out; |
| 545 | out << "HTTP/1.1 200 OK\r\n" |
| 546 | << "Content-Length: " << strlen(body_to_send.c_str()) << "\r\n" |
| 547 | << "Content-Type: " << content_type << "; charset=utf-8\r\n" |
| 548 | << "Cache-Control: no-cache\r\n" |
| 549 | << "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n" |
| 550 | << "Accept-Ranges: bytes\r\n\r\n"; |
| 551 | if (strcmp(request_info->request_method, "HEAD") != 0) { |
| 552 | out << body_to_send; |
| 553 | } |
| 554 | |
| 555 | mg_write(connection, out.str().c_str(), out.str().size()); |
| 556 | } |
| 557 | |
| 558 | void Server::SendHttpBadRequest(struct mg_connection* const connection, |
| 559 | const struct mg_request_info* request_info, |
no test coverage detected