7 #include <boost/lexical_cast.hpp>
8 #include <rapidjson/document.h>
9 #include <rapidjson/stringbuffer.h>
10 #include <rapidjson/writer.h>
14 using contrail_rapidjson::Document;
15 using contrail_rapidjson::StringBuffer;
16 using contrail_rapidjson::Value;
17 using contrail_rapidjson::Writer;
24 const std::string &msg,
int status_code) {
25 const std::string response =
26 "HTTP/1.1 " + boost::lexical_cast<std::string>(status_code) +
" OK\r\n"
27 "Content-Type: application/json; charset=UTF-8\r\n"
29 boost::lexical_cast<std::string>(msg.length()) +
"\r\n" "\r\n" + msg;
30 session->
Send((
const u_int8_t *)(response.c_str()),
31 response.length(), NULL);
38 Document::AllocatorType &a = document.GetAllocator();
40 document.AddMember(
"error", v.SetString(error_msg.c_str(), a), a);
42 Writer<StringBuffer> writer(strbuf);
43 document.Accept(writer);
void SendResponse(HttpSession *session, const std::string &msg, int status_code)
virtual bool Send(const uint8_t *data, size_t size, size_t *sent)
void SendErrorResponse(HttpSession *session, const std::string &error_msg, int status_code)