#include "messageutils.h" #include namespace MessageUtils { PIHTTP::MessageMutable jsonReply(PIHTTP::Code code, const PIJSON & json) { PIHTTP::MessageMutable msg; msg.setCode(code); msg.setBody(json.toJSON(PIJSON::Compact).toUTF8()); msg.addHeader("Content-Type", "application/json; charset=utf-8"); return msg; } PIHTTP::MessageMutable errorReply(PIHTTP::Code code, const PIString & message) { PIJSON j = PIJSON::newObject(); j["error"] = message; return jsonReply(code, j); } PIHTTP::MessageMutable successReply(const PIJSON & json) { return jsonReply(PIHTTP::Code::Ok, json); } PIHTTP::MessageMutable noContent() { PIHTTP::MessageMutable msg; msg.setCode(PIHTTP::Code::NoContent); return msg; } } // namespace MessageUtils