src/server.cpp
void Server::send_http_json_response(struct mg_connection *nc, const Json::Value& response, int code, const string& reason) {
    if (response == Json::nullValue) {
        send_http_error(nc, 404, "Not Found");
    } else {
        //string buf = response.toStyledString();
        Json::StreamWriterBuilder wbuilder;
        //wbuilder["indentation"] = "\t";
        std::string buf = Json::writeString(wbuilder, response);
        //string buf = response.asString();

        mg_printf(nc, "HTTP/1.1 %d %s\r\n"
                          "Content-Length: %d\r\n"
                          "Content-Type: application/json\r\n\r\n"
                          "%s",
                  code, reason.c_str(),
                  (int) buf.size(), buf.c_str());
    }
}
// very opinionated response (404 on null values)
very opinionated response (404 on null values)
very opinionated response ( 404 on null values )
void Server::send_http_json_response(struct mg_connection *nc, const Json::Value& response, int code, const string& reason) {
    if (response == Json::nullValue) {
        send_http_error(nc, 404, "Not Found");
    } else {
        Json::StreamWriterBuilder wbuilder;
        std::string buf = Json::writeString(wbuilder, response);
        mg_printf(nc, "HTTP/1.1 %d %s\r\n"
                          "Content-Length: %d\r\n"
                          "Content-Type: application/json\r\n\r\n"
                          "%s",
                  code, reason.c_str(),
                  (int) buf.size(), buf.c_str());
    }
}
void Server :: send_http_json_response ( struct mg_connection * nc , const Json :: Value & response , int code , const string & reason ) { if ( response == Json :: nullValue ) { send_http_error ( nc , 404 , " " ) ; } else { Json :: StreamWriterBuilder wbuilder ; std :: string buf = Json :: writeString ( wbuilder , response ) ; mg_printf ( nc , " \r \n " " \r \n " " \r \n \r \n " " " , code , reason . c_str ( ) , ( int ) buf . size ( ) , buf . c_str ( ) ) ; } }
very opinionated response (404 on null values)
very opinionated response ( 404 on null values )
//string buf = response.toStyledString(); //wbuilder["indentation"] = "\t"; //string buf = response.asString();