| 474 | } |
| 475 | |
| 476 | int Server::SendResponseToClient(struct mg_connection* conn, |
| 477 | const struct mg_request_info* request_info, |
| 478 | const std::string& serialized_response) { |
| 479 | LOG(TRACE) << "Entering Server::SendResponseToClient"; |
| 480 | |
| 481 | int return_code = 0; |
| 482 | if (serialized_response.size() > 0) { |
| 483 | Response response; |
| 484 | response.Deserialize(serialized_response); |
| 485 | return_code = response.GetHttpResponseCode(); |
| 486 | if (return_code == 0) { |
| 487 | this->SendHttpOk(conn, |
| 488 | request_info, |
| 489 | serialized_response, |
| 490 | HTML_CONTENT_TYPE); |
| 491 | return_code = 200; |
| 492 | } else if (return_code == 200) { |
| 493 | this->SendHttpOk(conn, |
| 494 | request_info, |
| 495 | serialized_response, |
| 496 | JSON_CONTENT_TYPE); |
| 497 | } else if (return_code == 303) { |
| 498 | std::string location = response.value().asString(); |
| 499 | response.SetSuccessResponse(response.value()); |
| 500 | this->SendHttpSeeOther(conn, request_info, location); |
| 501 | return_code = 303; |
| 502 | } else if (return_code == 400) { |
| 503 | this->SendHttpBadRequest(conn, request_info, serialized_response); |
| 504 | return_code = 400; |
| 505 | } else if (return_code == 404) { |
| 506 | this->SendHttpNotFound(conn, request_info, serialized_response); |
| 507 | return_code = 404; |
| 508 | } else if (return_code == 405) { |
| 509 | std::string allowed_verbs = ""; |
| 510 | Json::Value additional_data = response.additional_data(); |
| 511 | if (additional_data.isObject() && additional_data.isMember("verbs")) { |
| 512 | allowed_verbs = additional_data["verbs"].asString(); |
| 513 | } |
| 514 | this->SendHttpMethodNotAllowed(conn, |
| 515 | request_info, |
| 516 | allowed_verbs, |
| 517 | serialized_response); |
| 518 | return_code = 405; |
| 519 | } else if (return_code == 501) { |
| 520 | this->SendHttpNotImplemented(conn, |
| 521 | request_info, |
| 522 | ""); |
| 523 | return_code = 501; |
| 524 | } else { |
| 525 | this->SendHttpInternalError(conn, request_info, serialized_response); |
| 526 | return_code = 500; |
| 527 | } |
| 528 | } |
| 529 | return return_code; |
| 530 | } |
| 531 | |
| 532 | // The standard HTTP Status codes are implemented below. Chrome uses |
| 533 | // OK, See Other, Not Found, Method Not Allowed, and Internal Error. |
no test coverage detected